A bicycle isn't properly stable even when the wheels are turning. It's statically stable, where it may keep it orientation with slight disturbances. But it will tend to fall over. It's the person on the bike adjusting their weight that makes the bicycle dynamically stable. Where it will return to its upright position reliably.
The gyroscopic effect does help the cyclist keep the bicycle dynamically stable. As you would know from using a bike. However, the cyclists is the main factor in keeping the bike upright. BMX cyclists often keep the bike upright when stationary, often with the brakes applied.
If you very accurately balance a bike and hold it while it gets up to speed on a treadmill it may stay upright for a while. However any small motion will through it off balance. The bike will also slow down relative to the treadmill as the force of the treadmill will push it backwards once you release the bike. I don't imagine it staying on the treadmill for more than a few seconds.
In order to keep it on the treadmill and upright you will have to pedal the bike to match the treadmill speed. You will also need to move weight on the bike to keep it upright. The moving weight will be the main thing that keeps it upright.
This will be very difficult as you need to very accurately match the speed of the treadmill to stay on it - unless you get a very long treadmill.
Does it matter if this in in a train? It would be the same as any other room, except the vibrations of the train would make it harder to balance the bike. When the train accelerates and decelerates the bike will see either more slip or the cyclist will have to counter the force caused by the changing speed by cycling faster or braking.
If it's on top of the train you would also need to counter the effect of drag when cycling on the treadmill.