You have to pay a second home tax if you are registered as living in two different places within Germany, one being your primary residency, e.g. Cologne and the second one being your secondary residence, e.g. in Magdeburg.
The second home tax is only levied in Magdeburg and not in Wernigerode and Halberstadt. Whether you are affected by the tax depends on the registration of your residence in Magdeburg (as your main or secondary residence).
You can find detailed information on the website of the city of Magdeburg.