There are people in various functions that can influence

where people end up sitting. The check-in staff, despatchers, cabin crew and pilots can all bring some influence to bear.
It all depends on space being available and catering, of course. What happens on board after the aircraft doors are closed is under he notional control of the captain, although doubtless some movement between cabins takes place without the knowledge of the captain, although it shouldn't.