Creating other relationships for memberships on behalf of an organization
I can think of two approaches.

One - instead of hook_civicrm_post, use use hook_civicrm_postProcess, like you describe, to grab the Contact A id.

Two - use hook_civicrm_post on the Membership object rather than the Contribution object.  This should get you Contact B's id.  You can then use an API get to look up the most recently created Relationship for Contact B, which should be Contact A.  Then use an API create to create your new Relationship.

I'd probably go with option two, personally.