Should you mention your ranking in specific courses in statement of purpose?
I'm assuming that you're talking about Ph.D. admissions, rather than masters' admissions, which often play by very different rules from department to department and institution to institution.

Comparing classes across institutions is virtually impossible, to the point where some graduate schools require you to state the textbooks associated with your undergraduate courses in order to evaluate you.  A better way to think about how grades relate to Ph.D. admissions is as a negative filter: if you have iffy grades, then you will not be considered.  If you have excellent grades, then you will be placed into a large pile of other excellent students, which is then sifted to see who also has interesting potential to do something besides problem sets.

As such, rather than putting down a rank, ask yourself this: are any of the classes you performed excellently in ones where the professor might be willing to write a letter recommending you for insight or creativity or something else beyond mere mechanical brilliance?  That will go much farther toward getting you admitted.