what is likely happening is that the top of the locknut is bottoming out on the top of the fork
and not allowing it to press against the threaded top cone or race to prevent loosening
to solve this
either
add a thin spacer between the top nut and the next component down
or
cut a few mm off the top of the fork
no matter how you solve it
make sure to leave enough of the threads of the locknut engaged that you dont risk stripping it out when tightening