As other comments and answers have suggested (perhaps indirectly), long division of polynomials—which is an algorithm of repeatedly putting in a term in the quotient that you want then dealing with the consequences—does the trick.
Instead, here's a pretty natural way that you might discover factoring a sum of cubes on your own. (It generalizes to sum of odd powers naturally.)
Perhaps you're messing around with Pascal's triangle and binomial powers (as one does), and you write down
$$
(a+b)^3 = a^3 + 3a^2b + 3ab^2 + b^3.
$$
Notice the $a^3 + b^3$. Let's isolate it:
$$
a^3 + b^3 = (a+b)^3 - (3a^2b + 3ab^2).
$$
Now, it's pretty clear that $3ab$ is a common factor of the last two terms. Let's pull it out:
$$
a^3 + b^3 = (a+b)^3 - 3ab\, (a + b).
$$
Now, $(a+b)$ is a common factor, which is fantastic news. Pull it out and clean up the contents of the quantity on the right:
\begin{align}
a^3 + b^3
&= (a+b) \, \bigl((a+b)^2 - 3ab \bigr) \\
&= (a+b) \, \bigl(a^2 + 2ab + b^2 - 3ab \bigr) \\
&= (a+b) \,(a^2 - ab + b^2).
\end{align}
Voilà, sum of cubes!
Incidentally, you can produce this identity in one chain of equations, but the adding and subtracting the same quantity (in blue) seems to come out of nowhere. It is, of course, motivated by knowing what a binomial cube looks like and the previous messing around.
\begin{align}
a^3 + b^3
&= (a^3 \color{blue}{{}+ 3a^2b + 3ab^2} + b^3) \color{blue}{{}- (3a^2b + 3ab^2)} \\
&= (a+b)^3 - 3ab\,(a+b) \\
&= (a+b) \, \bigl((a+b)^2 - 3ab \bigr) \\
&= (a+b) \,(a^2 - ab + b^2) \\
\end{align}