Per the Star Wars Databank article on the B-Wing, the pilot decides whether to lock the gyro to a local horizon or, presumably, to let the cockpit align itself with the orientation of the ship itself.
The B-wing's command pod has a unique gyroscopic control system. The
pilot can orient it so that it always stays level with a horizon line.
No matter which way the B-wing may maneuver laterally, its pilot
remains upright.
B-WING FIGHTER - StarWars.com
This is discussed at some length in the (Legends) video game Star Wars: Rogue Squadron II: Rogue Leader
Because the cockpit is surrounded by a unique gyro-stabilization
system, the pilot always remains stationary, even as the rest of the
ship rotates during flight.
And in this image from Star Wars: Card Trader. Note that the image was originally taken from a set of Legends blueprints found in the Essential Guide to Vehicles factbook.
And you can see how it would work in practice.