HMRC is to scrap a costly tax error code that left millions of pensioners thousands of pounds worse off - and they can claim it back.