Inconsistent voltage on buck converter (TPS54240)
Did you use an autorouter?

@Andyaka I kinda did, yes. Routing a PCB was surprisingly time
consuming and actually wasn't that easy. So I used an autorouter and
edited the traces afterwards to, for instance, remove 90° angles in
traces.

The routing, component placement and track widths are pretty bad in very important areas. Don't use an autorouter unless it's a last resort like for a backplane etc. where there are many repeated steps in the process.
Problems


In light blue is the tortuous path taken from the inductor around the PCB to connect to C17 and C18 (the main bulk capacitors).
In purple is the far-too-long track from the switcher output to the flyback diode and inductor
The track widths are far too thin in my opinion and their length makes a big loop that could emit nasty interference to any close-by sensitive circuits.


D5 should be right up close to the switcher and should ground directly to C17-C19 forming an island. That island should only connect to the rest of the design (not the power supply) at one unambiguous point to avoid switching currents creeping into ground areas of sensitive circuits.

Recommendations

L1 should be alongside D5
C17 and C18 should be butted up to the above
Then C19 and C20
The ground connection of R31 (not visible in the layout) should make a connection directly to the island of ground for D5, C17, C18, C19 and C20
Any other ground points associated with the switcher should be teed off from that ground island.

Regarding the inductor
I see nothing in the data sheet that rules it out but, whenever I design a switcher, I pick an inductor that has a specified self-resonant-frequency (SRF) just to ensure that it is fit for purpose; in other words, if your switching frequency is (say) 200 kHz, I would want to pick an inductor that has an SRF of at least 1 MHz. Unfortunately I didn't see this stated in the data sheet nor can I say that the supplier has a decent quality system and decent tolerances. This last bit is about being careful who you choose. For instance, if one of the major recognized electronic component vendors was offering it in their catalogue I would be assured that the original manufacturer was OK.
Something like this: -