Y axis is changing randomly

I am making a 2d platformer type game and on the player controller script (it is like the one from the live training)
whenever I walk the y axis kind of bounces, it goes up by about 0.3 to 0.4 every time the an arrow key is pressed:

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {
     
        [HideInInspector] public bool facingRight = true;
        [HideInInspector] public bool jump = false;
        public float moveForce = 200f;
        public float maxSpeed = 1f;
        public float jumpForce = 500f;
        public Transform groundCheck;



        private float lockPos = 0;
        private bool grounded = false;
        private Animator anim;
        private Rigidbody2D rb2d;
     
     
        // Use this for initialization
        void Awake ()
        {
            anim = GetComponent<Animator>();
            rb2d = GetComponent<Rigidbody2D>();
        }
     
        // Update is called once per frame
        void Update ()
        {
            //locks position values
            transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.z, lockPos, lockPos);

            grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("ground"));
         
            if (Input.GetButtonDown("Jump") && grounded)
            {
                jump = true;
            }
        }
     
        void FixedUpdate()
        {
            float h = Input.GetAxis("Horizontal");
         
            anim.SetFloat("Speed", Mathf.Abs(h));
         
            if (h * rb2d.velocity.x < maxSpeed)
                rb2d.AddForce(Vector2.right * h * moveForce);
         
            if (Mathf.Abs (rb2d.velocity.x) > maxSpeed)
                rb2d.velocity = new Vector2(Mathf.Sign (rb2d.velocity.x) * maxSpeed, rb2d.velocity.y);
         
            if (h > 0 && !facingRight)
                Flip ();
            else if (h < 0 && facingRight)
                Flip ();
         
            if (jump)
            {
                anim.SetTrigger("Jump");
                rb2d.AddForce(new Vector2(0f, jumpForce));
                jump = false;
            }
        }
     
     
        void Flip()
        {
            facingRight = !facingRight;
            Vector3 theScale = transform.localScale;
            theScale.x *= -1;
            transform.localScale = theScale;
        }
    }

also the z rotation would go to 90 whenever i walked so I put in
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.z, lockPos, lockPos);
and that has stopped that problem but I would like to know what caused it in the first place,

Thanks

BUMP