two-table-over  functional relationship: maintaining referential integrity
You add a (redundant) unique constraint on (study_id, id) on both the treatment and visit tables. Then let the foreign keys from session refer to these unique constraints by including study_id into the respective foreign keys.

Then your condition will automatically be satisfied.

The unique constraints are not quite as superfluous as they seem, because the foreign key constraint on study_id should be indexed anyway.

To put it into SQL:

ALTER TABLE treatment
   ADD UNIQUE (study_id, id);

ALTER TABLE visit
   ADD UNIQUE (study_id, id);

ALTER TABLE session
   DROP CONSTRAINT session_treatment_id_fkey,
   DROP CONSTRAINT session_visit_id_fkey,
   ADD FOREIGN KEY (study_id, treatment_id) REFERENCES treatment (study_id, id),
   ADD FOREIGN KEY (study_id, visit_id) REFERENCES visit (study_id, id);