Build the Privateer wonder.
Otherwise it's difficult. Occasionally the UP holds a vote to appoint a guard for them, but the measure is short lived, maybe 2-3 years.
The only other options I see is to:
1. Carefully plan out trade routes
away from hostile civilizations. This isn't always possible, though.
2. Lightly arm freighters & then build military starbases all along their route. Not very feasable, particularly since the bases themselves will come under attack.
3. Establish fleets to patrol trade routes and destroy enemies and pirates.
I've never armed freighters. I have put Sensors on them as "headlights" lighting up regions as they travel.
One tactic I do use is to have a reserve of them in the event of war, to immediately establish new trade routes. If you don't mind cheesy manuvers, you can buy freighters from other civilizations, immediately turn them around and establish a new route. I've found through testing that a route is established between their planet and your nearest one.
Late game, keeping Minor races around - even if they have no tech or other use for you - is a way to at least have
some trade revenue when its just you and one other opponent.