As a general rule you don't need an online connection to play games on PS5. However, some games - particularly dedicated online multiplayer titles - do require an internet connection to function properly.
Games that require an internet connection for all or even part of their functionality will generally specify this on product packaging (or product listing page in the case of online purchases). Always be sure to check before you buy.
Online connection is required to download digital games from the PlayStation Store.
Click here to find out more about connecting your PS5 to the internet.