You may have supposed the phone was waterproof, but Apple never said it was. Here is what Apple says:
iPhone 7, iPhone 7 Plus, iPhone 8, iPhone 8 Plus, iPhone X, iPhone XS, iPhone XS Max, iPhone XR, iPhone SE (2nd generation), iPhone 11 Pro, iPhone 11 Pro Max, iPhone 11, iPhone 12 Pro, iPhone 12 Pro Max, iPhone 12, and iPhone 12 mini are splash, water, and dust resistant and were tested under controlled laboratory conditions; iPhone 12 Pro, iPhone 12 Pro Max, iPhone 12, and iPhone 12 mini have a rating of IP68 under IEC standard 60529 (maximum depth of 6 meters up to 30 minutes); iPhone 11 Pro and iPhone 11 Pro Max have a rating of IP68 under IEC standard 60529 (maximum depth of 4 meters up to 30 minutes); iPhone XS, iPhone XS Max, and iPhone 11 have a rating of IP68 under IEC standard 60529 (maximum depth of 2 meters up to 30 minutes); and iPhone 7, iPhone 7 Plus, iPhone 8, iPhone 8 Plus, iPhone X, iPhone XR, and iPhone SE (2nd generation) have a rating of IP67 under IEC standard 60529 (maximum depth of 1 meter up to 30 minutes). Splash, water, and dust resistance are not permanent conditions and resistance might decrease as a result of normal wear. Do not attempt to charge a wet iPhone; refer to the user guide for cleaning and drying instructions. Liquid damage not covered under warranty.
Here’s a user tip on this subject→Understanding Water Resistance - Apple Community