Just a guss:
1. The system is probably able to sort out guests by their lounge entry credentials by airlines (both *G and lounge membership).
2. On a periodical basis (weekly, monthly, etc), there is probably a process to net the "due to" or "due from" balances between each airlines in the alliance. For exmaple: United recorded 100 LH passengers using the United Clubs, and LH recorded 90 UA passengers using LH lounges in the same period. After netting off, UA will pay LH for 10 passenger-entries.
3. I suspect the airlines flown is the one paying not the airlines which the passengers hold the *G status with. I stand to be corrected. This is just my own guess.
Let's say I fly CA, and use my UA *G status to use SQ lounge. CA is getting all the revenue from the ticket I purchased. UA gets nothing in the process. I anticipate SQ will charge CA. I expect SQ and CA will go through the net-off set i described in 1 and 2 above. Otherwise, UA is losing money from this partucular flight activity.
Others feel free to speculate...