If an airliner turns back midway, how is the route planned?
A diversion is a diversion, regardless of whether it is to the nearest airport, back to your origin airport or some other airport that is attractive, which may depend on what sort of facilities are needed (gates, fuel, maintenance, etc.).
The pilot simply tells ATC their new destination, and ATC amends their flight plan and gives the pilot a new clearance to follow. Depending on how far it is, the pilot (with the help of their dispatcher, if applicable) may request a specific route, or they may leave it up to ATC. That flight plan update is also automatically forwarded to all the relevant FIRs, just like the original version was.