Two motors can replace physical gears
keeping the central cogs lubricated would be too hard, so putting a ratcheting bearing on the big cog (second shaft) will at least keep it from moving at high speed. And it maybe OK if it were coated with Teflon of possibly a dry wax lube.
The way around an efficiency robbing, reliability reducing, maintenance and weight increasing gearbox is to instead invest that money and weight, is the right size motor and gear it properly. Locomotives driven by electric motors don't have multi-speed gearboxes. Tesla engineers initially thought the same as you and tried to make the Roadster a 2 speed and learned better after wasting millions, so now Tesla's are single speeds. Brammo uses or used them on their consumer emoto's, but more to give potential customers something familiar than out of need as riders generally use just one gear, but their racing emoto is a single speed like all the other electric racers.
But if you can't use the right size motor due to laws, you need gears.
Retro-direct two speed
----- Motor spins CCW it engages the 13t small size freewheel and pulls the chain with it 13t/50+t reduction ratio (AKA=low gear) and the 24t south paw freewheel just freewheels going along with the chain.
----- Motor spins CW it engages the 24t south paw freewheel and pulls the chain with it 24t/50+t reduction ratio (AKA=high gear) and the 13t small size freewheel just freewheels going along with the chain.
I cannot swear that is it adaptable to a bicycle.
/ how to motorize a big heavy vehicle/ Hub Motors / How much power do you really need?