It's been done but how well it works depends on the controller used, the motor used, specific situation at the time, road conditions, tire type, loading of the trailer, trailer hitch design, if the bike has suspension or not (which affects where loading goes because of pivoting actions over terrain), what kind of braking the controller can do, etc. It also depends on the battery's ability to accept whatever regen current is generated, continuously for as long as the worst case conditions would occur...
Unless you have a high enough load in the trailer to force traction on the trailer wheel during braking, it may just lock up the wheel and drag the tire across the road surface. If the trailer is just a single wheel and the forces from it are not completely aligned with the bike, and the trailer can pivot sideways at all, it may just jackknife with the load sliding to the side and around to yank the back of the bike sideways. If the trailer can only pivot up and down, then that won't happen, but traction can still be lost and you end up dragging the tire, wearing flat spots in it.
If all you have is the typical on/off one-level regen braking most controllers have, then the force may only vary with speed, higher speed giving more force and making it more likely to break traction. Usually these also cease trying to brake (or being able to) below some not all that slow speed.
If you use an FOC controller then they usually have proportional / variable braking response that you can adjust in the controller setup for both how much response and how fast it works up to and how slow it will go down to.
So with the typical controller with on/off regen, you might not get enough braking to do anything useful, or it might always be so hard that it tends to break traction, and you just get what you get depending on the situation.
FOC or anything else with variable regen (controlled by throttle or brake lever or whatever, by the rider) gives you the chance to control the braking amount so it stays below the traction threshold. You may still not get enough braking, but at least you can keep traction all the time.
Braking also doesn't regenerate all the energy into the battery--a significant part is lost in the motor itself, and the phase wires, and the controller. In normal city braking this doesnt' matter usually, it just spikes the heat momentarily and then that cools off over the ride. But continuous downhill braking could overheat the motor, wires, and/or controller, and damage them.
Another consideration for using regen braking for long durations and under some other conditions is whether there is any chance of refilling the battery beyond full charge. If this could ever be a problem, some special circumstances that can be very bad can happen. Controllers often (usually) have an HVC for regen setup so that if battery is above that point it won't even allow regen, but if it's a lower voltage battery design than the controller was built or setup for, it wont' kick in. Common controllers are not adjustable for this...FOC should be adjustable, and some others may be.
First, if the battery or controller doesn't have a way to know this is happening and stop it, the cells can be overcharged, which can damage them, leading to future risk of fire.
If the controller HVC works, it prevents this, but if not...then if the battery does have a way to protect itself (common port BMS so it can shut off regen current charging), and it does do this, the generated voltage from the motor without any load on it now will suddenly shoot way up, and can be beyond what the controller parts can take, so it blows up...most commonly taking out the phase FETs which then locks up the wheel (or at least makes it very draggy and hard to turn). Sometimes it also takes out the LVPS in the controller, or other parts; in this event if the failure is of the rare wrong kind it can also take out the motor hall sensors and throttle/pas sensors, etc.