It is in SN 16.11.
‘Your outer robe of patches is soft, Kassapa.’–‘Venerable sir, let the Blessed One accept my outer robe of patches, out of compassion.’–‘Then will you wear my worn-out hempen rag-robes? ’–‘I will, venerable sir.’ Thus I offered the Blessed One my outer robe of patches and received from him his worn-out hempen rag-robes.
However, the English translation doesn't mention that the Buddha wore a cloth wrapped to a dead body instead it just mentions worn-out hempen rag-robes. In the pali version it says the robe was paṃsukūlāni (rags discarded on the ground).
The Buddha has obtained it from the dead body of a servant named Punna lying in the cemetery (Thisthis part is probably in the commentary of Samyutta Nikaya). He wore this robe until he exchanged it with Maha Kassapa.