You need M1 Max or M1 Pro to support two external displays from Thunderbolt. Then you need to connect the 4K and 5K to separate Thunderbolt ports.
With M1 or M2 (not Max or Pro), you can only connect one external display to Thunderbolt. Connect the 5K by itself. To connect another display, use a DisplayLink Adapter. You can connect the DisplayLink adapter to the LG UltraFine 5K. To connect the 4K to the DisplayLink Adapter, you need a bi-directional USB-C to DisplayPort cable since I don't think there are any DisplayLink adapters that support USB-C display. A bi-directional USB-C to DisplayPort cable won't let you use the USB features of the 4K (audio, camera, USB, brightness control), therefore you should get a Belkin Charge and Sync cable instead, or a Wacom Link Plus, which both add a separate USB connection. Remember that a display using DisplayLink is not connected to the GPU - it is connecting using USB. This means video data must be compressed (from 16 Gbps for 4K60 down to ≈1 Gbps).
Of course, this will only work if the LG UltraFine 4K is the 24 inch version which supports USB-C and Thunderbolt connection. The original LG UltraFine 4K 21 inch only supports Thunderbolt connection.