I use the following definition for a variety: Let $k$ be a fixed field (not necessarily algebraically closed), then a scheme $X\to\operatorname{Spec}k$ is called a variety if $X$ is integral, and the structure morphism $X\to\operatorname{Spec}k$ is separated and of finite type. We say that a variety $X\to\operatorname{Spec}k$ is projective if we can consider $X$ as a closed subscheme of $\mathbb{P}_k^n$ for some $n$, i.e. if we can factor $X\to\operatorname{Spec}k$ as $X\hookrightarrow\mathbb{P}_k^n\to\operatorname{Spec}k$ for some $n$.
Now, my intuition about rational maps is that they fail to be ordinary maps when they have some sort of "singularity", and intuitively, this isn't the case when the target scheme is projective. This is my (incomplete) work so far:
Let $U\subseteq X$ be some nonempty open and let $f:U\to Y$ be a morphism of varieties. Now, if we can extend $U\to Y\to\mathbb{P}^n$ to some morphism $g:X\to\mathbb{P}^n$, then since $g(U)\subseteq Y\subseteq\mathbb{P}^n$, then $$g(X) = g(\overline{U})\subseteq \overline{g(U)} = \overline{Y} = Y\subseteq\mathbb{P}^n$$ so that we can factor $g$ through $Y$, and therefore we may replace $Y$ with $\mathbb{P}^n$.
Now, given a map $f:U\to\mathbb{P}^n$ with $U\subseteq X$, then it suffices to show that if $X$ is affine, then $f$ can be uniquely extended to $X$, because in that case, we can simply cover by affine opens and glue uniquely. Furthermore, we can assume that $U$ is a distinguished open $D(f)$.
Therefore, we have reduced to the following theorem: Let $X = \operatorname{Spec}(k[x_1,\ldots,x_m]/I)$ be an affine variety over $k$, let $f\in k[x_1,\ldots,x_m]/I$ be some nonzero element, and let $f:X\vert_{D(f)}\to\mathbb{P}^n$ be a morphism of $k$-varieties, then $f$ can be extended uniquely to a morphism $g:X\to\mathbb{P}^n$ of $k$-varieties.
However, I'm at a loss for how to prove this. Are there any examples that can help illustrate why this is true or false?