I can't speak for Italy, but in Spain, a tourist visa has nothing to do with it.
Foreigners, non residents and non-EU citizens can legally establish a business here, but again, complicated, bureaucratic, and expensive. It's quite a bit easier if you own the property you'll be offering, since you'll already be on the tax registry.
But then there's also tourist licensing, which, here in the Balearics, is outrageously expensive to establish. 3500€ per bed, if I remember correctly (one time fee) . You should NOT attempt to offer any type of STR tourist let without licensing, if required in your jurisdiction. Here, it's up to 40000€ fine and a permanent shutdown, and most booking platforms won't accept you without it.