I’m trying to remove the nut so I can replace the freewheel cassette thing but I can’t remove it since it’s rusted I’ve tried using WD-40 but it didn’t work
Can you remove the nut from the non-drive side? If so, you should be able to remove the entire axle and either replace it, remove the drive side nut with the axle out of the hub (out it in a vise etc), or even reinstall adjusting the non-drive side.
If the non-drive side is also seized (likely), Rust dissolver (as already suggested) does not work, application of heat might help.
Personally I would resort sacrificing the nut fairly early - nut and axles are cheap to replace, and a lot of time and knuckle skin can be wasted getting a seized nut off. A nut splitter would be the goto tool, or drilling the nut flats and spitting with a screwdriver (refer How to remove this stripped brake bolt?, it has a lot of answers that a relevant to this situation. )
I always go for plan B - oxy-acetylene - which has never ever let me down! Get the offending item nice and cherry-red, and try again with the spanner/socket. If not, plan C is to blow it off, again with oxy-acetylene. Very carefully (it's hardly a diy job) but the thread can be saved by someone who knows what they're doing.
That was the only way to remove a trailer bearing years ago abroad - luckily, the recovery left me in a knacker's yard, with o-a available, although it took hours of persuasion to let them let me use it, and seconds to do the job!