With $M$ stacks we can sort $F_M$ numbers
(where $F_M$ is the $M$-th Fibonacci Number)
This is an answer for the call for generalization in OP's answer, by generalizing his/her method.
For comparison with other answers, the asymptotic $N$ as $M$ goes to infinity is $C\varphi^N$ (where $\varphi$ is the golden ratio: $1.61803398875\ldots$) for some constant $C$. Why is this true can be read in the Wikipedia article.
Note that, compared to user3294068's answer, which asymptotically uses $C2^{\frac{N}{2}} = C\sqrt{2}^N$, this algorithm is definitely better for larger $N$ ($\sqrt{2} = 1.41421356\ldots$).
I'll divide this answer to three sections: a visualization of the algorithm, the general idea how it works, - which leads to the final part - and the general procedure for any $M$.
Visualization of Algorithm
This section will explain the algorithm in OP's answer through step-by-step visualization.
For completeness, I'll copy his algorithm here, slightly modified to generalize the algorithm:
The rule is simple to follow: move each card to the next stack, unless the number is forbidden for that stack in which case you put it on the following one. When all the cards are on final stack, the numbers are sorted.
For $M=6$, the forbidden numbers are as follows:
Stack 1: none.
Stack 2: 1,6,7.
Stack 3: 3,4.
Stack 4: 7,8.
Stack 5: 1,2,3.
Stack 6: none.
Due to my limited knowledge of LaTeX, I'll draw the stacks sideways, from bottom to top.
So, initially we have stack 1 ($S_1$) and that it has nothing forbidden ($\{\}$), containing the number $1$ to $8$. We do not know in what order they are initially, so we group them together, like this:
$$
\begin{eqnarray}
S_1\{\}&:& \boxed{12345678}
\end{eqnarray}
$$
The grouping means the number in that group can be in any order.
Next, we have Stack 2 forbidding three numbers ($S_2\{1,6,7\}$), and Stack 3 forbidding two numbers ($S_3\{3,4\}$), like this:
$$
\begin{eqnarray}
S_1\{\}&:& \boxed{12345678}\\
S_2\{1,6,7\}&:&\\
S_3\{3,4\}&:&
\end{eqnarray}
$$
Then we put the numbers from Stack 1 to Stack 2 if it's not forbidden, else put in Stack 3. We'll end up like this (red means it's no longer there):
$$
\begin{eqnarray}
S_1\{\}&:& \color{red}{\boxed{12345678}}\\
S_2\{1,6,7\}&:& \boxed{23458}\\
S_3\{3,4\}&:& \boxed{167}
\end{eqnarray}
$$
Next, we have Stack 4 with its 2 forbidden numbers:
$$
\begin{eqnarray}
S_1\{\}&:& \color{red}{\boxed{12345678}}\\
S_2\{1,6,7\}&:& \boxed{23458}\\
S_3\{3,4\}&:& \boxed{167}\\
S_4\{7,8\}&:&
\end{eqnarray}
$$
Then, after distributing Stack 2 to Stack 3 and 4 we have this:
$$
\begin{eqnarray}
S_1\{\}&:& \color{red}{\boxed{12345678}}\\
S_2\{1,6,7\}&:& \color{red}{\boxed{23458}}\\
S_3\{3,4\}&:& \boxed{167}\boxed{258}\\
S_4\{7,8\}&:& \boxed{34}
\end{eqnarray}
$$
Note that in Stack 3, the group containing $258$ is on top of the group containing $167$, although in each group the order is arbitrary. So at this point Stack 3 might contain $671285$ or $761258$, but not $168257$.
This means, when splitting Stack 3 to Stack 4 and 5, group containing $258$ is split before the group containing $167$, so we have the following:
$$
\begin{eqnarray}
S_1\{\}&:& \color{red}{\boxed{12345678}}\\
S_2\{1,6,7\}&:& \color{red}{\boxed{23458}}\\
S_3\{3,4\}&:& \boxed{167}\color{red}{\boxed{258}}\\
S_4\{7,8\}&:& \boxed{34}\boxed{25}\\
S_5\{1,2,3\}&:& \boxed{8}
\end{eqnarray}
$$
$$
\begin{eqnarray}
S_1\{\}&:& \color{red}{\boxed{12345678}}\\
S_2\{1,6,7\}&:& \color{red}{\boxed{23458}}\\
S_3\{3,4\}&:& \color{red}{\boxed{167}\boxed{258}}\\
S_4\{7,8\}&:& \boxed{34}\boxed{25}\boxed{16}\\
S_5\{1,2,3\}&:& \boxed{8}\boxed{7}
\end{eqnarray}
$$
Note that at Stack 5, each group contains only one element, this means there is no variation, and so at this point, we can be sure that Stack 5 contains $8$ at the bottom and $7$ on top of it. Continuing this, we have:
$$
\begin{eqnarray}
S_1\{\}&:& \color{red}{\boxed{12345678}}\\
S_2\{1,6,7\}&:& \color{red}{\boxed{23458}}\\
S_3\{3,4\}&:& \color{red}{\boxed{167}\boxed{258}}\\
S_4\{7,8\}&:& \color{red}{\boxed{34}\boxed{25}\boxed{16}}\\
S_5\{1,2,3\}&:& \boxed{8}\boxed{7}\boxed{6}\boxed{5}\boxed{4}\\
S_6\{\}&:& \boxed{1}\boxed{2}\boxed{3}
\end{eqnarray}
$$
And finally moving the whole Stack 5 into Stack 6 will give us sorted from $1$ at the bottom to $8$ at the top.
Insights
So, observing the process above, we see that the algorithm works by splitting the numbers into multiple groups, each containing less elements than before, ensuring that when the group size finally reach 1, they are all in order.
Therefore, to generalize this, we need to find how to split the numbers into groups of smaller size.
First, note that the restriction to use only 3 groups means if we have $k$ group in Stack $i$, we can split them into $k$ groups in Stack $i$ and $k$ group in Stack $i+1$. This implies the number of groups in Stack $i$, which comes from Stack $i-2$ and Stack $i-1$, is at most the sum of number of groups in Stack $i-2$ and Stack $i-1$. Formally, if $G_i$ denotes the number of groups in Stack $i$, we have:
$$ G_i = G_{i-1} + G_{i-2} $$
Initially we have only one group in Stack 1, and later we can have at most 1 group in Stack 2. This gives $G_1 = G_2 = 1$, which makes $G_i = F_i$, where $F_i$ is the $i$-th Fibonacci number. So with $M$ stacks, we can sort $F_M$ numbers (precise answer).
Next, we can use the similar reasoning to prove the optimality of this algorithm. Note that at the end we must have $N$ groups, each containing one number. So considering the first insight above, the maximum number of groups at Stack $M$ is $F_M$, therefore we can't have less than $M$ stacks to sort $F_M+1$ numbers. So, by taking $M$ such that $F_{M-1} < N \leq F_M$ (which would be about $\lfloor \log_\varphi \left(N\sqrt{5}+\frac{1}{2}\right)\rfloor$ according to the Wikipedia article), it is the minimum required (and sufficient) to sort $N$ numbers.
Generalization Procedure
Now we come to the interesting part, how can we generalize this to any $M$, not just $M=6$ like in the example? More specifically, how should we assign the set of forbidden numbers for each Stack?
For this, we can work backward from Stack $M$ down to Stack 1, assuming maximum possible $N$. Note that the set of forbidden numbers for $M$ stacks will work for any $N$ less than the maximum $N$ (the numbers is guaranteed to be sorted at Stack $M$).
First, we know that there are $F_M = N$ groups at Stack $M$ at the end. One step before (that is, after we emptied Stack $M-2$), there are $F_{M-1}$ groups in Stack $M-1$ and $F_{M-2}$ groups in Stack $M$.
Next, we know that in order for those first $F_{M-2}$ numbers to be in Stack $M$, they must be forbidden at Stack $M-1$ (because those numbers come only from Stack $M-2$, so those numbers can't ever be inside Stack $M-1$). So we now know the forbidden numbers at Stack $M-1$.
To continue, we note that in the algorithm, we split groups, so now we need the reverse, which is to merge groups. We know that the $i$-th top-most group in Stack $M-1$ would have come from the same group in Stack $M-2$ as the $i$-th top-most group in Stack $M$. This enables us to reverse the process, and continue numbering the forbidden numbers in the same way until we get back to Stack 1.
For example, here is the procedure for $M=7, N=13$:
$$
\begin{eqnarray}
S_7\{\}&:& \boxed{1}\boxed{2}\boxed{3}\boxed{4}\boxed{5}\boxed{6}\boxed{7}\boxed{8}\boxed{9}\boxed{10}\boxed{11}\boxed{12}\boxed{13}
\end{eqnarray}
$$
$$
\begin{eqnarray}
S_6\{1,2,3,4,5\}&:&\boxed{13}\boxed{12}\boxed{11}\boxed{10}\boxed{9}\boxed{8}\boxed{7}\boxed{6}\\
S_7\{\}&:& \boxed{1}\boxed{2}\boxed{3}\boxed{4}\boxed{5}\color{red}{\boxed{6}\boxed{7}\boxed{8}\boxed{9}\boxed{10}\boxed{11}\boxed{12}\boxed{13}}
\end{eqnarray}
$$
$$
\begin{eqnarray}
S_5\{11,12,13\}&:&\boxed{56}\boxed{47}\boxed{38}\boxed{29}\boxed{1\ 10}\\
S_6\{1,2,3,4,5\}&:&\boxed{13}\boxed{12}\boxed{11}\color{red}{\boxed{10}\boxed{9}\boxed{8}\boxed{7}\boxed{6}}\\
S_7\{\}&:& \color{red}{\boxed{1}\boxed{2}\boxed{3}\boxed{4}\boxed{5}\boxed{6}\boxed{7}\boxed{8}\boxed{9}\boxed{10}\boxed{11}\boxed{12}\boxed{13}}
\end{eqnarray}
$$
$$
\begin{eqnarray}
S_4\{4,5,6,7\}&:&\boxed{1\ 10\ 11}\boxed{2\ 9\ 12}\boxed{3\ 8\ 13}\\
S_5\{11,12,13\}&:&\boxed{56}\boxed{47}\color{red}{\boxed{38}\boxed{29}\boxed{1\ 10}}\\
S_6\{1,2,3,4,5\}&:&\color{red}{\boxed{13}\boxed{12}\boxed{11}\boxed{10}\boxed{9}\boxed{8}\boxed{7}\boxed{6}}\\
S_7\{\}&:& \color{red}{\boxed{1}\boxed{2}\boxed{3}\boxed{4}\boxed{5}\boxed{6}\boxed{7}\boxed{8}\boxed{9}\boxed{10}\boxed{11}\boxed{12}\boxed{13}}
\end{eqnarray}
$$
$$
\begin{eqnarray}
S_3\{1,10,11\}&:&\boxed{3\ 4\ 7\ 8\ 13}\boxed{2\ 5\ 6\ 9\ 12}\\
S_4\{4,5,6,7\}&:&\boxed{1\ 10\ 11}\color{red}{\boxed{2\ 9\ 12}\boxed{3\ 8\ 13}}\\
S_5\{11,12,13\}&:&\color{red}{\boxed{56}\boxed{47}\boxed{38}\boxed{29}\boxed{1\ 10}}\\
S_6\{1,2,3,4,5\}&:&\color{red}{\boxed{13}\boxed{12}\boxed{11}\boxed{10}\boxed{9}\boxed{8}\boxed{7}\boxed{6}}\\
S_7\{\}&:& \color{red}{\boxed{1}\boxed{2}\boxed{3}\boxed{4}\boxed{5}\boxed{6}\boxed{7}\boxed{8}\boxed{9}\boxed{10}\boxed{11}\boxed{12}\boxed{13}}
\end{eqnarray}
$$
$$
\begin{eqnarray}
S_2\{3,4,7,8,13\}&:&\boxed{1\ 2\ 5\ 6\ 9\ 10\ 11\ 12}\\
S_3\{1,10,11\}&:&\boxed{3\ 4\ 7\ 8\ 13}\color{red}{\boxed{2\ 5\ 6\ 9\ 12}}\\
S_4\{4,5,6,7\}&:&\color{red}{\boxed{1\ 10\ 11}\boxed{2\ 9\ 12}\boxed{3\ 8\ 13}}\\
S_5\{11,12,13\}&:&\color{red}{\boxed{56}\boxed{47}\boxed{38}\boxed{29}\boxed{1\ 10}}\\
S_6\{1,2,3,4,5\}&:&\color{red}{\boxed{13}\boxed{12}\boxed{11}\boxed{10}\boxed{9}\boxed{8}\boxed{7}\boxed{6}}\\
S_7\{\}&:& \color{red}{\boxed{1}\boxed{2}\boxed{3}\boxed{4}\boxed{5}\boxed{6}\boxed{7}\boxed{8}\boxed{9}\boxed{10}\boxed{11}\boxed{12}\boxed{13}}
\end{eqnarray}
$$
$$
\begin{eqnarray}
S_1\{\}&:&\boxed{1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\ 10\ 11\ 12\ 13}\\
S_2\{3,4,7,8,13\}&:&\color{red}{\boxed{1\ 2\ 5\ 6\ 9\ 10\ 11\ 12}}\\
S_3\{1,10,11\}&:&\color{red}{\boxed{3\ 4\ 7\ 8\ 13}\boxed{2\ 5\ 6\ 9\ 12}}\\
S_4\{4,5,6,7\}&:&\color{red}{\boxed{1\ 10\ 11}\boxed{2\ 9\ 12}\boxed{3\ 8\ 13}}\\
S_5\{11,12,13\}&:&\color{red}{\boxed{56}\boxed{47}\boxed{38}\boxed{29}\boxed{1\ 10}}\\
S_6\{1,2,3,4,5\}&:&\color{red}{\boxed{13}\boxed{12}\boxed{11}\boxed{10}\boxed{9}\boxed{8}\boxed{7}\boxed{6}}\\
S_7\{\}&:& \color{red}{\boxed{1}\boxed{2}\boxed{3}\boxed{4}\boxed{5}\boxed{6}\boxed{7}\boxed{8}\boxed{9}\boxed{10}\boxed{11}\boxed{12}\boxed{13}}
\end{eqnarray}
$$
Bonus: Generalization of the problem
Now, the above solves the problem of finding maximum $N$ given $M$ stacks, clearing one stack at a time, and using only 3 stacks at a time. What if we remove that last restriction? How many numbers can we sort? (Ok, I admit that I've been nerd-sniped)
Note that if we can use 4 stacks, then we can split a Stack into 3 stacks, and so the number of groups in a stack depends on the previous 3 stacks, giving us Tribonacci Number with $F_{(3)}(1) = F_{(3)}(2) = 1$, for which the asymptotic ratio is about $1.83929$.
For fun, here is the final diagram when we can use 4 stacks ($M=5, N=F_{(3)}(5)=7$):
$$
\begin{eqnarray}
S_1\{\}&:& \color{red}{\boxed{1234567}}\\
S_2\{3,4,7\}&:& \color{red}{\boxed{1256}}\\
S_3\{1,6,7\}&:& \color{red}{\boxed{34}\boxed{25}}\\
S_4\{1,2,3\}&:& \color{red}{\boxed{7}\boxed{6}\boxed{5}\boxed{4}}\\
S_5\{\}&:& \boxed{1}\boxed{2}\boxed{3}\boxed{4}\boxed{5}\boxed{6}\boxed{7}
\end{eqnarray}
$$
The more stacks we can use, the higher the asymptotic ratio is. You can check Tetranacci Number, Pentanacci Number, and so on in this very helpful Wikipedia article, which states that the limit of the ratio is $2$. So asymptotically, we can sort $C\cdot2^M$ numbers with $M$ stacks (actually the exact number is $2^{M-2}$ if we are allowed to use all available stacks).
With this, finally I can tell OP, that the problem is solved. (reference to this comment)
Ok, you might notice that I'm heavily influenced by What-If XKCD style. That's my favorite reading!