The camera changes its proper position


My camera sometimes when it contact with another object (for example when player is running for some time into cube) moves itself to another position.Any ideas how I can fix that?
(camera should be directly on the head )

This code is assigned to CamHolder:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveCam : MonoBehaviour
{
    public Transform CamPosition; 
    // Update is called once per frame
    void Update()
    {
        transform.position = CamPosition.position;
    }
}

And this to camera itself:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CamMovement : MonoBehaviour
{
    public float sensX;
    public float sensY;

    public Transform orientacja;

    float xRotation;
    float yRotation;
    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }

    // Update is called once per frame
    void Update()
    {
        float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
        float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;

        yRotation += mouseX;

        xRotation -= mouseY;

        xRotation = Mathf.Clamp(xRotation, -90f, 90f);


        transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
        orientacja.rotation = Quaternion.Euler(0, yRotation, 0);
    }
}