If you created the solutions, then, ethically, there is nothing wrong with making them public. If you take a class that has specific rules, however, you need to agree to those rules. But that is a different matter.
You do some students a disservice by publishing answers, in my view. Reading a solution to a problem is a much different educational process than producing it yourself. Education isn't primarily about "answers" but the process that lets the student generate the answers.
But, ethically, you can publish your own work, even if it was "sparked" by something you read as an exercise in a book.
But, for your CLASS, you need to consult the professor and see if there are any published rules.
Note that when a professor is asked for help on an exercise, they do their best job if they give the student some minimal hint that gets them past any misconception or block that they might have, but still permits creativity in the student. Giving them a solution blocks that avenue of creativity. Think about that and how you contribute to the educational process by publishing.
For some books (some of mine, for example) the exercises are much more important than the text itself. If a student can do all of the exercises with only minimal help (other than the text) then they will have a deep knowledge of the material. If they they do none of them then their knowledge is very superficial.
Note, however, that while you can publish your own solutions, you probably cannot publish the questions themselves without a copyright violation.