All definitions in mathematics are a matter of consensus, and not some divinely-inspired set of principles handed down from Olympus. We mathematicians are allowed to define any word to mean whatever we like it to mean. There is nothing holy about the right triangle definition of the cosine function, and we shouldn't be afraid to slaughter that sacred cow and adopt a different definition of it helps.
To that end, I am going to define two distinct functions:
Let $\triangle ABC$ be a triangle in which the angle at $C$ is a right angle. Let $a$ denote the length of the side which is opposite the angle $A$, let $b$ denote the length of the site which is opposite $B$, and let $c$ denote the length of the hypotenuse. See the figure, below.

Let $\theta$ denote the measure of the angle $A$, and note that $\theta$ must be between $0$ and $\pi/2$, exclusive. Define the function $f : (0,\pi/2) \to \mathbb{R}$ by
$$ f(\theta) = \frac{b}{c}. $$
Note that this ratio depends only on $\theta$, as any two right triangles with an angle measuring $\theta$ will be similar, and the similarity constant will cancel in the division.
You might notice that $f$ is precisely the cosine function, as defined in the question. However, I am very intentionally not calling it "the" cosine function, and am giving it an entirely different name in order to avoid confusion.
Let $\ell$ be a ray which originates at the origin and meets the positive $x$-axis at an angle $\theta$, where $\theta$ could be any real number. The ray $\ell$ will intersect the unit circle at a point $(x,y)$.

Define a function $g : \mathbb{R} \to \mathbb{R}$ by
$$ g(\theta) = x. $$
That is, $g(\theta)$ is the $x$-coordinate of the point where the ray $\ell$ meets the unit circle.
A priori, the two functions $f$ and $g$ appear to have nothing to do with each other. One is defined for all real numbers, while the other is only defined on a small interval; one is defined to be the ratio of two lengths in a right triangle, while the other is defined to be the $x$-coordinate of a point on the unit circle. These two functions seem to be completely different.
However, it can be shown (by putting $A$ at the origin and $\ell$ along the hypotenuse—see the figure, below) that these two definitions give exactly the same result for any angle between $0$ and $\pi/2$. That is
$$ \theta \in (0,\pi/2) \implies f(\theta) = g(\theta). $$

As such, it is entirely reasonable to say that $g$ is an extension of $f$ into a larger domain: whenever both functions are defined, they agree with each other, but $g$ is defined for a larger set of values. Because $g$ extends $f$, there is no real reason to think of them as distinct functions, and so we sneakily give them the same name, and define
$$ \cos(\theta) = \begin{cases}
\text{your choice of $f(\theta)$ or $g(\theta)$} & \text{if $\theta \in (0,\pi/2)$, and} \\
g(\theta) & \text{if $\theta \in (-\infty,0] \cup [\pi/2,\infty)$.}
\end{cases} $$
Note that this definition of the cosine function does not require any appeal to a right triangle. We can choose to think about right triangles in the part of the domain where it might make sense to do so, but we are not required to do so. And for angles outside of this narrow interval where right triangles make sense, we completely discard any notion related to triangles, and work with the more general function.