This feature is known as "immersive mode" and was first introduced in Android 4.4 KitKat. It allows the app to hide the notification/status bar and even the navigation bar.
For the official method, the developers of the app need to implement this feature on their app. Though, some ROMs may also provide this feature built-in, sometimes also known as "expanded desktop mode", e.g. CyanogenMod/LineageOS, OnePlus.
Otherwise, some 3rd-party apps may help to force immersive mode in all apps:
Note that by using these apps, the keyboard may not work properly.
Due to some security features in Android, users will not have access to the keyboard in many apps while in immersive mode.
Beware that your keyboard may not work in Immersive Mode, which is why having the toggle in the notification shade is so handy.