Ensure same tenant in a Many to Many relationship
This is almost an anti pattern if you ask me.


All accounts have a company
All account_groups have a company
They're all linked through a linking table which also has a company.


So, everything has a company: except when it doesn't? And if a company has a subsidiary you're in a world of trouble. It may make sense. But, what you seem to be doing is creating buckets which you can relate to in order to emulate hierarchy; however, the hierarchy is easier to just have in all it's glory.

CREATE TABLE accounts (
  accountid             serial PRIMARY KEY,
  name                  text   NOT NULL,
  email                 text,
  contact_name_given    text,
  contact_name_surname  text,
  parent_accountid      int    REFERENCES accounts
);

INSERT INTO accounts (accountid,name,email,contact_name_given,contact_name_surname,parent_accountid) VALUES
  (1,'ACME', 'company@acme.com',null,null,null),
  (2,'ACME Sales', 'sales@acme.com', 'John D', 'Supervisor', 1),
  (3,'Evan Carroll', 'ecarroll.sales@acme.com', 'Evan', 'Carroll', 2);


Then get the list with a RECURSIVE CTE

WITH RECURSIVE t(accountid, name, email, contact_name_given, contact_name_surname, level)
AS (
  SELECT
    accountid,
    name,
    email,
    contact_name_given,
    contact_name_surname,
    0
  FROM accounts
  WHERE parent_accountid IS NULL
  UNION ALL
    SELECT
      a2.accountid,
      a2.name,
      a2.email,
      a2.contact_name_given,
      a2.contact_name_surname,
      t.level+1
    FROM t
    JOIN accounts AS a2
      ON ( t.accountid = a2.parent_accountid )
)
SELECT *
FROM t;


 accountid |     name     |          email          | contact_name_given | contact_name_surname | level 
-----------+--------------+-------------------------+--------------------+----------------------+-------
         1 | ACME         | company@acme.com        |                    |                      |     0
         2 | ACME Sales   | sales@acme.com          | John D             | Supervisor           |     1
         3 | Evan Carroll | ecarroll.sales@acme.com | Evan               | Carroll              |     2
(3 rows)


Now you just need to give logical names to the level = 0,1,2 if that's something the task really requires. or make the schema more accommodating of different types of entities in the hierarchy.