The changes are not applied because the Put method is called for the TargetObject property, but the SetInfo method is called for the $user variable. Despite the fact that the same user is referenced by TargetObject property and the $user variable, these are considered different objects in terms of PowerShell. Moreover, there is no need to additionally bind to the user as the TargetObject property of the $Context variable already represents an instance of the user object on which the script is executed.
As far as we understand, you need to change property values once the user last name has changed. If so, there is actually no need to use a PowerShell script. It can be done using a business rule triggering After updating a user. The rule should look like the following:
If you still need to update property values using a PowerShell script, you can use the approach like the following:
$fullName = "%firstname% %lastname%"
$userName = "%firstname%.%lastname%"
# Update property values
$Context.TargetObject.Put("userPrincipalName", $userName + "@domain.com")
$Context.TargetObject.Put("mail", $userName + "@domain.com")
# Save the changes