It's perfectly legal.
If you are still receiving any salary, then the tax on the ESA will only be collected on a monthly or weekly basis depending how on how frequently you are paid. You are not paying tax on ESA that you have not received yet.
If you come off ESA in the current tax year and go back to work, then all you need to do is call the tax office on the number here and have the the figure for ESA shown in your tax code amended to the actual sum that you received. The reason it is there is to avoid you owing tax at the end of the current tax year.
I hope this helps but let me know if you have any further questions.