Mosfet are driven by voltage, that's why it won't work, needs 12-15V between gate and source for lowest Rds.
When you apply 24V to the gate, it conducts... then you have 24V at the source, the voltage difference between gate and source would be gone (0).
Ok reality it won't turn off, but self-regulate in the ohmic region due the gate threshold voltage, it will find the equilibrium for the load current, RDS voltage drop and VGs.
If you measure Vgs, you probably see around 3-4V.
You need a P-ch MOSFET, a high-side driver or bootstraping the mosfet.
The bootstrap circuit is easy, but will only work if the PWM never runs at 100% (DC).
24V is too much for the gate! You must add a 12/15V tener.