What happens if a signed PowerShell script is edited afterwards, even by adding one comment, and why?
It no longer runs under AllSigned: the hash of the current content no longer matches the signed hash, so PowerShell reports the signature as invalid (HashMismatch).
The signature covers a hash of the script content. Any change, a comment, a space, a different line ending, changes the hash. On execution PowerShell recomputes the hash and compares it with the one inside the signature block; they differ, so the file's contents "might have been tampered with" and it is refused. Get-AuthenticodeSignature .\script.ps1 shows the status HashMismatch.
This is the integrity guarantee working as intended: PowerShell cannot tell a harmless comment from an inserted backdoor, and should not try to. After a legitimate change, the developer simply signs again. The rule follows: sign as the very last step, after all edits.
Go deeper:
Microsoft Learn: about_Signing โ signature validation and what invalidates it.