In 2 Peter 2:5-7, Peter explains what happened in the flood and why the waters came upon the earth. God did not send the flood, but rescued people from it. This explanation is identical to what Jesus said about the flood in Matthew 24. Since sin cannibalizes itself, the sin of the people at the time of the flood brought the waters of destruction upon themselves.
In seeking to understand what is going on in the account of the flood and why the waters that came upon the earth, we must understand the ANE cosmology. The waters of the flood cause the world to revert the the chaos of a pre-creation state. The flood reveals cosmic warfare between God and Yamm, the god of chaos and storms.