In a highly unusual ruling, an employment tribunal ordered the government department to give Ellie Preston her old job back and to pay her £1318 in lost wages.
Mrs Preston, who has a three-year-old son, worked part-time as an assistant officer at the Debt Management Centre in Cumbernauld, North Lanarkshire, for eight years.
She took time off work for abdominal surgery in November 2011 and after being unable to return to work because of continued ill health she was sacked the following August.
But the tribunal ruled she should have been given time to recuperate and should have been allowed to return once she was better.
It ruled she had been unfairly dismissed and there was no reason why she should not be reinstated.
"There was no evidence that there were sour relations between the claimant and any of her managers. There was no evidence that the case had engendered bad feeling," said the chairman's judgement.
A spokesman for the Public and Commercial Services Union, which represented Mrs Preston, said it was highly unusual for a tribunal to rule in favour of reinstatement. He said: "Of 5000 cases where unfair dismissals claims have been upheld, only five reinstatement orders have been made."
A HMRC spokesman said: "HMRC reviews all ET decisions to see if there are lessons to be learned. "