system
Given the following post, respond as if you're commenting on Reddit:
human
How do space vehicles know how to orientate themselves? (Specifically unmanned spacecraft)

Do they use a gyroscope system? Or the planets magnetic field?

(I got curious watching a Scott Manley video on YouTube, he talked about the pitch and yaw of the recent ‘Astra’ rocket launch and I realised I’d never questioned the method - hard to get a straight-forward answer out of google)
gpt
Commonly-used sensors are: coarse sun sensors, gyroscopes, magnetometers, star trackers, and GPS receivers.  Common actuators are: reaction wheels, magnetic torquers, thrusters, and (less commonly) control moment gyros.

Coarse sun sensors are simply photovoltaic solar cells.  Arrange several of them around your spacecraft, and you can get an idea of where the Sun is.

Gyroscopes (aka inertial measurement units, inertial reference units) measure angular rate.  There are several technologies available: MEMS gyros (which you might have in your phone), fiber optic gyros, ring laser gyros, and hemispherical resonating gyros.

Magnetometers measure the magnetic field, like a 3-D compass.

A star tracker is like a video camera that can compare its image with an internal star catalog, and so figure out where in the sky it is pointing.  This is the most accurate off-the-shelf sensor in common use.

A GPS receiver tells you your position, not your orientation.  But position is a good thing for a spacecraft to know, too.

Reaction wheels exert torque by action/reaction.  Spin one up clockwise, it makes your spacecraft spin counterclockwise.  Use several, properly arranged, and you can control all three axes of your spacecraft with precision.

Magnetic torquers are big electromagnets.  Energize one, and it tries to line itself up with the local magnetic field.  You can use this to exert torque on your spacecraft.  Magnetic torquers aren't precise, but they are very commonly used in combination with reaction wheels in low Earth orbit.

Thrusters are rockets.  Push mass out one way, the spacecraft moves the other way.  You can exert both forces and torques with thrusters, so you can change your orbit as well as control your attitude.  (Everything else on this list is torque-only.)

Control moment gyros (CMGs) are like reaction wheels except different.  Instead of exerting torque by changing the wheel spin rate, you keep the wheel spinning at a constant rate and use a gimballed mount to change the CMG's orientation in the spacecraft.  Spinning masses resist having their axis of spin re-oriented (look up "gyroscopic stiffness"), so the result is a torque on the spacecraft.  CMGs are bulkier, more power-hungry, and more expensive than reaction wheels, but they provide orders of magnitude more torque.  If you are very agile (like some remote imaging spacecraft) or just huge (like ISS), CMGs are worth it.

I hope that gives you enough of a start that you can get more traction with google.