WHEREVER in the world you go and reside, you need work permit if you engage personally in any activity that brings revenue. that is called work, as you know. the only exception is if you have a PASSIVE revenue like stock dividends, rent income and whatnot.
so you’ll need work permit in spain.
since you are an independent consultant, you are autonomous. which goes as ‘autonomo’ in spain. self employed. you can either register as such and declare your income and pay taxes as an individual, or set up a small simple company and do it like that. if your monthly income is at or higher than 5000 euro, latter is the better option.