A mechanism to disconnect the battery when the trailer is towed. ...
The industry does it this way: The breakaway switch is mounted on the tongue of the trailer. The switch is normally-open. It is held open by a thing that looks like a plastic clothes-pin. If the clothes-pin is pulled out of the switch body (takes a bit of force), the contacts close, immediately locking the trailer brakes. To rearm the switch, you have to push the clothes-pin back into the body of the switch.
The clothes-pin is attached to a small-diameter (0.1") steel cable. The other end of the steel cable is clipped to the rear-bumper of the towing vehicle, independant of the normal trailer coupling, the safety chains, or the electrical connection between the trailer and the towing vehicle.
If the trailer were to become uncoupled from the towing vehicle at speed, and the safety chains are not able to keep the trailer hooked to the towing vehicle, then the electrical connection would be severed (leaving nothing to power the electric brakes if there is no battery in the trailer). As the clothes-pin is pulled out of the breakaway switch body by the cable presumably still attached to the towing vehicle, that is supposed to lock the brakes on the trailer to stop it.
At that moment, the source of the 12V required to apply the brakes (about 2A per wheel) must come from the trailer-mounted 12V 5Ah SLA battery. Note that supplying these type of electric wheel brakes with a steady 12V will lock up the wheel so that they skid. During normal towing, the brake controller in the towing vehicle modulates the braking by varying the Pulse Width of the braking current. The braking controller is actually quite sopisticated, and bases the PWM to the trailer brakes on the rate of de-acceleration of the towing vehicle (using a MEMS accelerometer).