The (net) payment to you is after deductions (tax, NI etc). You pay back the gross amount (net payment + deductions) and then you have to claim the deductions back from HMRC. As ever, the onus is on you.
I'm lucky enough that this never happened to me, and in any case, my service was pre-JPA.
However, it can't be right that the MOD make an error, say an overpayment of GBP1000, say GBP 650 to you, and GBP350 to HMRC, and then claim back GBP 1000 from you. That's utterly ridiculous.
Moreover, the overpayment might push you into a higher tax bracket, then you'd be paying higher tax for the rest of the year on the (now) corrected pay rate.
JPA's been in for some years now. Why hasn't this been sorted out? Don't the Services have Flag/General/Air officers in charge of personnel issues?