There is a misconception that all hacking is illegal. However, hacking is simply identifying weaknesses in a device -- whether it is a PC, smartphone, or another physical object -- and software, including apps, and attempting to exploit them.
This could include a computer network, old tech equipment, or a website's backend control system.
Hacking, in itself, doesn't automatically mean unauthorized entry. There are companies out there that ask for ethical hackers to test their software for weaknesses and will reward them financially for their findings.
It is only when a hacker uses their skills for unauthorized and criminal purposes, theft, or destruction that it becomes illegal. This could include breaking into a network to deploy malware or stealing confidential information.