Users who are “staff” are always allowed to change their username - are you sure the user you are testing with is not a “moderator” or “admin”?
Although it doesn’t technically prevent (in a secure way) the user from changing their username / real name you could add the following to both a CSS and “mobile CSS” customisation:
.user-preferences {
.pref-username,
.pref-name {
display:none;
}
}
This would just hide the controls for viewing and editing username and real name.