Before a pentest starts, a formal discussion occurs between the pentester and the system owner.The tools, techniquest and targets are agreed on. The resulting documentm, called the statement of work (SOW) includes verbiage giving pentesters permission to perform the pentest.
Anything that falls outside of this agreement is considered unauthorised.
get-out-of-jail-free card
SOW can also offer legal protection if you make certain mistakes within the scope defined by the SOW.
This is especially necessary when performing pentests against buildings, as it may be useful when being questioned by building security or law enforcement.
Also, pentesting services companies are held against legal frameworks and industry accreditation.