When everyone starts web development for the first time, they hear iframes are terrible! Don’t use them, they’re slow and weird there’s nothing they could ever be good for!
There’s a good reason that we’re taught this. Embedding an iframe in your webpage is similar to having two different browser tabs open. The iframe has it’s own DOM and loading events that aren’t shared with the parent window, this can lead to clunky behaviours when interacting with the iframe. Scrolling on mobile is often the major concern.
The simple answer is, when you need to run untrusted third party code in your webpage.
More to come on iframe sandboxing, communication between iframes, scrolling and interactions.