Not so straightforward. To be able to hijack a mech, you'll want to focus your firepower on the orange glass part to break it and then kill the pilot before the mech is destroyed. A sniper rifle is recommended but not mandatory. If the mech hasn't been destroyed, you'll be able to approach it and take control of it.
The mech will automatically explode if it is the last enemy you kill during a fight so make sure to keep anybody else alive before attempting the method above.
Credit to Fauved for their
guide.