You only have to leave the sterile area if you're going into or out of T5. No customs required.
It may be a little tight, depending on how quickly you're able to disembark the plane and which gates you arrive at/depart from. Could be a 5-minute walk or could be a 15-minute brisk walk. My only concern would be if you're the last to disembark and have to walk from one end of T2 to the other end of T1.