Trouble when accessing old after deleting a row in postgrsql
To have a realistic demo case, you need to populate the tables, not just create them.
Your title says &quot;after deleting a row&quot;, but your trigger is clearly a &quot;before&quot; trigger.
If you (attempt to) delete a row from people which has no corresponding entry in accounts, then athleteSum naturally becomes NULL.  What else would it do?  If you wish to avoid this, you need to take steps to avoid it.  Convert to zero?  Throw an error?  I don't know, only you can know.

addBalance := ROUND(athleteSum / peopleCount::INTEGER);

You are dividing two integers.  The result of integer division is already an integer.  No rounding is necessary.  Shouldn't it be (peopleCount-1)?  Otherwise you are distributing the value back to the row that was just (attempted to be) deleted.

FOR person IN 0..peopleCount LOOP

WHERE peopleID = person;


Why would you expect the peopleID to be densely packed between 0 and peopleCount?  Especially since you just attempted to delete one of those intervening values?

RETURN NEW;

For a delete trigger, NEW is NULL. Returning NULL prevents the delete from actually happening.  Is that what you want?