I am writing a document where I have a situation where I need to describe that a function $ f(n) $ equals $ n $ in a certain case but does not equal $ n $ in other cases.
I am not sure how to write it cases. Here are the two alternatives I am considering:
Alternative 1
Therefore we conclude that $$ f(n) \begin{cases} = M & \text{if } n = M, \\ \ne M & \text{if } n < M. \\ \end{cases} $$
Alternative 2
Therefore we conclude that, $$ \begin{cases} f(n) = M & \text{if } M = 10, \\ f(n) \ne M & \text{if } M < 10. \\ \end{cases} $$
I don't think I have seen either form in math textbooks and math literature. What is the conventional way of expressing such an idea? Also, consider that I have given only two cases here as an example but there may be three or more cases too.
The most common way I know to express such things is with iff (if and only if) in text, not in an equation.
So in your first example, we have that $f(n) = n$ if and only if $n = M$.
If you want it as an equation: $$f(n) = n \Leftrightarrow n=M$$
About your comment:
If you only want partial cases, the cases environment is even worse. In this, we assume that the list of cases is complete. For example, something like $$f(n) = \begin{cases} 5 & n = 7 \\ 2 & n = 3\end{cases}$$ is not where we use cases, as we only give two values, not the whole definition of the function.
So if you only have partial information and don't know all the values, I would strongly suggest not to use cases. Otherwise, a reader (as happened to me) would assume that this are all cases, i.e. the case $n > M$ is excluded somehow.