I still think the other answers are a little too complicated. Our goal is to find an $n+1$-degree polynomial $P_{n+1}(x)$ on the interval $[a,b]$ that is orthogonal to any $n$-degree polynomial $Q_{\leq n}(x)$ on the interval $[a,b]$, i.e.
$$\int_a^b P_{n+1}(x) Q_{\leq n}(x) dx = 0.$$
The LHS is an integral of a product, so hopefully one's first instinct would be to try integration by parts. Allow me to use the notation of the tabular method: https://kevinboone.me/parts.html (though I can't typeset the arrows here, even if it's possible with more technology) . We have 2 options: we can put $P_{n+1}$ in the derivative column, or the integral column. Let us look at putting it in the derivative column first:
$$\begin{array}{r|c|c}
\text{row }\# & \frac{d}{dx} & \int \\ \hline
0 & \color{blue}{P_{n+1}(x)} & Q_{\leq n}(x) \\
1 & P_{n+1}'(x) & \color{blue}{\int Q_{\leq n}}\\
\vdots &\vdots & \vdots \\
n+1 & \color{red}{\text{constant}} & \ldots \\
n+2 & 0 & \color{red}{\ldots}
\end{array}$$
The left column ("row $0$") starts with degree $n+1$, decreasing in degree by 1 each time, until on row $n+1$ it becomes constant (degree $0$). The last term in the integration by parts is then some [constant] times some high degree antiderivative of $Q_{\leq n}(x)$, which we have no control over in making $0$ upon evaluation $(\bullet)|^{x=b}_{x=a}$.
Let us try the other option, putting $P_{n+1}$ in the integral column:
$$\begin{array}{r|c|c}
\text{row }\# & \frac{d}{dx} & \int \\ \hline
0 & \color{blue}{Q_{\leq n}(x)} & P_{n+1}(x) \\
1& Q_{\leq n}'(x) & \color{blue}{\int P_{n+1} }\\
\vdots & \vdots & \vdots \\
n& \color{red}{\text{constant}} & \ldots \\
n+1& 0 & \color{red}{(\int)^{n+1} P_{n+1}}
\end{array}$$
In the scenario where $Q_{\leq n}$ has degree $n$ (on row $0$ of the table), then on row $n$, it will be degree $0$, namely a constant; on the right/integral column, on row $n+1$ we will have the $(n+1)$th antiderivative of $P_{n+1}(x)$. So, the result of this integral by parts table is (at most) $n$ terms:
$$\int_a^b P_{n+1}(x) Q_{\leq n}(x) dx = \textstyle \Big[Q_{\leq n}(x) \cdot \int P_{n+1}(x)\Big]\bigg|_{x=a}^{x=b} - \ldots + (-1)^n \Big[\text{const} \cdot (\int)^{n+1} P_{n+1}(x)\Big]\bigg|_{x=a}^{x=b}$$
(The notation is a bit fiddly, but I hope you can see that the ideas are actually quite simple. If I was writing on a whiteboard in front of you, I could just draw slope-$(-1)$ ovals in the table representing each term, without having to use all this notation, but oh well.)
Again, recall that we have control over what $P_{n+1}$ is, and we have just found that all it needs to be is a degree $n+1$ polynomial s.t. its $1$st, $2$nd, ..., $(n+1)$th antiderivative all vanish at both $x=a$ and $x=b$.
This is still a little hard to think about, but it becomes much easier, if I tell you to think about the problem backward: start with a polynomial $A(x)$ of degree $2(n+1)$ (supposed/destined to be the $(n+1)$th antiderivative of $P_{n+1}$), so that its $0$th, $1$st, ..., $n$th derivatives vanish at $x=a$ and $x=b$ (and then taking $P_{n+1}(x):= (\frac d{dx})^{n+1} A(x)$, we're done!)
And indeed, hopefully one is familiar (from working with Taylor series, or orders of zeroes and poles in complex analysis) that the derivative of a function vanishing to order $M$ at a point $x=x_0$ vanishes to order $M-1$ at $x=x_0$. So, taking $A(x)=(x-a)^{n+1} (x-b)^{n+1}$ (indeed of degree $2(n+1)$), the $0$th, $1$st, ..., $n$th derivatives vanish at $x=a$ and $x=b$, as desired (and indeed the $(n+1)$th derivative is a polynomial of degree $n+1$, as desired!)