You can only do that by changing the history. Which on master is not good thing to do. If it's last commit in master you are able to do that. But after that you need to notify whole team so they will update as soon as possible. If you are tagging and this commit has tag as well it will be removed. It might affect other tools as well.
You can use the commands you posted or checkout the last commit from the feature branch, squash it, merge to master before this PR was merged, merge it and again force push it.
Personally I'll rather leave the whole history there. Hope that the developer at least did good job commiting and the commits makes sense (atomic, etc).
For the future I'll introduce automatic way for that. Never depend on the humans, they will always make mistakes. So if you have gitlab, github then enforce the commit squash. It's possible to enforce that in almost any git solution. Also only some people should be allowed to merge and it should never be the author of the feature. This is also because of security (ASVS 1.1.1)