Freeze transform.rotation.x

I press key = script freezes transform.position.x
I press another key = script unfreezes transform.position.x

Is that possible?

It is possible yes. The question is : what makes the object move in the first place?
It’s always better to act on the cause than on the consequences.

If your object is using a RigidBody, you can change the RigidBody properties so that it doesn’t move, such as isKinematic = true, or velocity = Vector3.zero.

If your object is under the influence of a script, then disable that other script, or modify it so that it doesn’t change the object’s position under further notice.