I've never seen such a sloppy job! Doesn't look factory to me ... and makes me wonder if the Dealer knew about the leak and did that to stop it?
Another possibility - and I hope this isn't it ... is - it took a rear end hit and that's part of the finished repair?
Before going back to the Dealer, you could take it to a car wash and sit back there to watch the water coming in, or even better - have someone spray the top of the vehicle with a garden hose while someone else is inside watching and listening for the water. You'd want to spray for about a minute, then stop, listen, and watch ... then repeat until the water starts to trickle in.
In the future, when buying any car (new or used) ... make sure you look over every inch of it. A co-worker just bought a sharp-looking 2020 Toyota Camry with about 20,000 miles on it and never looked in the wheel well! We were out in the parking lot leaving on Friday and he was showing me the stuff he may have overlooked:
1.) The very bottom tip/corner of the driver's door appears to be bent inward slightly (although the paint's not damaged). That's the kind of thing ... you gotta get down low and really take a close look!
2.) NO SPARE TIRE in the wheel well !! I told him to look up the Monroney sticker for the vehicle to see if it originally came with one, and if it did - I'd be right back at the Dealership to make them give me one (because the Dealer surely knew that spare was missing)! The well was rather large, and it looked pretty beat up back there (like there was one there previously), so I'm guessing it's supposed to have one, but then again ... so many new vehicles nowadays aren't coming with spares ... just a can of FIx-A-Flat (or whatever it is).
Just another bad idea from a bean-counter somewhere that's managed to catch on with most every automobile manufacturer.