I have the following map from the category of $k$-algebras to the category of sets:
$$\text{GL}_n:\mathbf{Alg}_k\rightarrow\mathbf{Set}:R\mapsto \text{GL}_n(R)$$
I would like to define its action on functions $f:R\rightarrow S$ to make it a functor.
Intuitively I would send $f:R\rightarrow S$ to $F:\text{GL}_n(R)\rightarrow \text{GL}_n(S):(a_{i,j})\mapsto (f(a_{i,j}))$
but nothing guarantees that the last matrix $(f(a_{i,j}))$ is indeed invertible.
Is there a way of showing that it is invertible? Or is it not the right way to define the action on functions?
Indeed this is a functor. It is usually thought of as a functor to the category of groups rather than sets, but never mind about that. The point is that if $A=(a_{ij})\in\text{GL}(R)$ then it has an inverse $B$, and $f(A)f(B)=f(AB)=f(I)=I$ where $f(A)=(f(a_{ij}))$, so that $f(A)$ has an inverse, as long as $f$ is a unital homomorphism, sending $1_R$ to $1_S$.