It's a security feature to prevent data loss. Basically, if you plug your phone into a charger or a computer that's malicious, your files are locked away until you enable the transfer. So it can only charge the battery.
On one ui 7, a malicious charger could actually be a little computer, once you connect, it starts transferring your files to itself. Rare but possible, especially with public chargers.
You can bypass it if you really want to, but it will lower security