Because the Quantum Realm is unpredictable. One can summarise many different things about whether or not it was because one of the two got stuck in a time vortex or not but the reality is that it's like a hyped up version of Sakaar.
Scott Lang: Have either of you guys ever studied quantum physics?
Natasha Romanoff: Only to make conversation.
Scott Lang: Well, five years ago, just before this Thanos guy... I went into a place called the Quantum Realm. It’s like its own microscopic universe. You can only get there if you’re incredibly small. Hope, she’s my... she was supposed to pull me out. But then Thanos happened. And I was stuck in there.
Natasha Romanoff: I’m sorry. It must’ve been a long five years.
Scott Lang: Okay, but that’s the thing. It wasn’t. For me, it was only five hours. The rules in the Quantum Realm aren’t like out here. They’re completely unpredictable. Is anybody gonna eat that sandwich?
Steve Rogers: Scott, what are you talking about?
Scott Lang: Time works differently in the Quantum Realm. Problem is, right now, it’s chaos, there’s no way to navigate it. But what if we could figure out a way to enter the Quantum Realm at a certain point in time...and come out in another. Like, before Thanos.
This is similar to what Hank tells Scott when he first mentions the Quantum Realm to him in Ant-Man.
Hank Pym: It means that you would enter a quantum realm.
Scott Lang: What does that mean?
Hank Pym: It means that you would enter a reality where all concepts of time and space become irrelevant as you shrink for all eternity. Everything that you know, and love, gone forever.
So, time passes differently for them both because of how time works in the Quantum Realm. For all we know Janet may have had some parts where 5 Quantum Realm hours = 5 Earth years and some where 5 Quantum Realm years = 5 Earth hours but it just happened to even out by the time she was rescued. It seems that Janet's plan for her rescue actually hinged on the probability fields lining up correctly, that might mean time also aligns at that point as well.
Janet van Dyne (through Scott): You have to meet me in these exact coordinates. In the wasteland, beyond the quantum void. It's very dangerous, especially on the human mind. So be careful. Time and space work very differently down here. You have two hours. After that, the probability fields will shift, and it'll be another century before they'll align like this again.
Ant-Man and the Wasp
Out of universe, however, this was done to make the reunion in Ant-Man and the Wasp more emotional. Presumably, what they did with Scott was for two reasons: make the Snap more impactful and to further the plot along so Scott could have the time machine idea.
"Ultimately you wanna have an emotional reunion with Michael Douglas, an emotional reunion with Evangeline Lily and our first instinct had always been specifically now Michelle Pfeiffer from that first movie. It felt like it should be somebody who’s the right age. As opposed to Michael Douglas with somebody who has not aged. Or Evangeline Lilly connecting with somebody who’s not aged. That just adds another layer of sort of sci-fi weirdness."
ScreenRant, Kevin Feige Explains How Time Works In The Quantum Realm