TLDR: It replaces "ground support" at less well equipped airports, or unequipped aprons.
The APU starts the main engines
Start with this: Your car has a battery, it starts the engine. Batteries on airplanes aren't big enough to start the main engines.
So the APU is a small engine that the batteries can start. The APU can then start the main engines.
But it also provides hotel power...
Once the APU is running, it also provides hydraulics, electrical controls, lighting and compressed air for engine start and air conditioning/heat for the cabin. It can also be used to power these hotel loads during takeoff, to avoid bleeding energy from engines. Or during flight, as famously used in the Flight 1549 ditching.
Before an airplane can be boarded, the HVAC must be run for quite some time to make the space habitable. You've heard warnings about not leaving babies or dogs in cars - same thing will happen to an airplane cabin left in the sun. That cabin could rise to 60-70C (140-160F) and you cannot board people into that!
Heating is simply: compressed air is pretty warm. Air conditioning uses a machine called a PACK.
If an airplane expects to sit on the ground for an extended period, they will usually shut off the main engines and run the APU to save fuel and engine hours.
...except at better-equipped airports
Shore-side equipment can deliver electrical and/or high-volume compressed air to a jetliner. The latter both starts engines and powers the heat and air conditioning.
The compressed air comes from a machine informally called a "huffer" - if you saw Top Gun: Maverick, you saw them start up a "huffer" to start up a jet fighter.
Simpler versions of this shore electric and air supply is a portable cart that is basically an APU on wheels. Better versions are built right into the apron or gate and are coming off grid power or a central air source. The huffer may be local to the gate, but electric.