Is it ethical to publish homework?
Sometimes when doing course work for university, I'd like to write
  about it on my website, or publish it in its entirety, because I think
  that other people might be interested in it.


This re-enforces your learning BUT will current students have access to it.

Once, a student from my University did this, and someone else copied from her. There was a big mess about this. Fortunately the student got a passing grade for the class.


  and most courses reuse homework questions and paper topics over
  multiple years.


and


  So my question is if it would be ethical for me to do so, and under
  which circumstances.


Instead of using exact question answer, can you create similar question and give solution. This way you are tutoring other people and making them think (and making yourself think), rather than giving the answers to students who just want to pass the class and forget what they "learned".