Is it ethical to profit by having my students buy my textbook?
This comes down to potentially conflicting principles.  Academic freedom requires that professors should be able to choose the most appropriate references for their courses, and of course the professor's own book will often be a perfect fit for the course that inspired it.  On the other hand, it's important to avoid even the appearance of assigning one's own book in order to make a profit: that would be offensive at any university, and often illegal at public universities (violating conflict of interest laws for government employees).  The American Association of University Professors statement on this subject elaborates on both of these issues, but doesn't find a good way of resolving the tension.

University policies are often more specific.  In many cases assigning one's own book either requires administrative permission or giving any royalties earned to the university.  See, for example, this report for a survey of the policies at eighteen public universities in the U.S.  My impression is that private universities are more likely to be flexible about this issue, but that's not based on a lot of data.

In practice, I doubt anyone cares very much unless the textbook is particularly expensive or the class is large, but in those cases I would strongly recommend donating the royalties to the department even if it is not required.  After all, you're then no worse off than you would have been if you had assigned someone else's book.  If you're not willing to do this, then it suggests that the royalties are attractive after all and may have played some role in the choice of text.

One special case is when you have self-published the book (or own the publishing company).  That looks terrible, because there you have full control over pricing and may be earning far more than typical royalties.  This is one of the few cases where I believe a strict rule is appropriate: if you are legally authorized to offer free or at-cost copies of your book to your students, then you should do so.  Anything less is clearly taking advantage of your students.