let's recall that the graph of a function passes the "vertical line test", however, that's not guarantee that its inverse will also be a function.
A function that has an inverse expression that is also a function, must be a one-to-one function, and thus it must not only pass the vertical line test, but also the horizontal line test.
Check the picture below, the left-side shows the function looping through up and down, it passes the vertical line test, in green, but it doesn't pass the horizontal line test.
now, check the picture on the right-side, if we just restrict its domain to be squeezed to only between [0 , π], it passes the horizontal line test, and thus with that constraint in place, it's a one-to-one function and thus its inverse is also a function, with that constraint in place, or namely with that constraint, cos(x) and cos⁻¹(x) are both functions.