Q:

Is urban exploration legal? Even if so, should I do it?

Intro
When I go exploring, I often find abandoned buildings, farms, factories. Near where I live, it's easy to find abandoned buildings in the mountains or the National Park.
I have an interest in Urbex. I admit some times when I go to the wild I'm actively looking for urban places and ruins to explore. I've been in some amazing places in my country, and I'm always looking for more. However, this is just an interest, not something I spend a lot of time thinking about.
Examples
Here's a few examples of places I've been (I don't own these photos):

Abandoned arabic building

Abandoned hotel (since the 80s I think), in the islands

Abandoned panoramic restaurant (since the 80s), right next to the country's capital

Abandoned thermal spa, popular during the beginning of XX century
Problem
How legal is it to enter these buildings? Can I explore with peace of mind knowing I'm doing nothing wrong or can this be considered trespassing, breaking & entering, burglary or even mischief, even if I'm doing nothing wrong?
I only enter a building if there is an open door (or window, gate, even holes in the walls or fences) and I never break anything. I like to have the same approach as I have in the wild: leave no trace. In my opinion, this is still the wilderness and you can actually find good examples of local flora and fauna inside these buildings.
Also, if there is a sign stating "Private property" or "No enter", I respect the signs and move on. There's plenty more to explore out there.
The arabic building from the picture above, for example, is abandoned but belongs to a complex of buildings on the same area, which I suppose belong to the same owner. As far as I know, there are people who own this building and who are easily identifiable, so I did not go inside.
I understand the laws will be different from country to country, but probably the principles will be the same? And how can I find the relevant laws and analyze them?
Thank you in advance, respect the world.
EDIT
To clarify, the photos were taken in Portugal; but since I also travel around the world (mainly Europe), I would like to know the general principles behind these laws. The answers given so far are interesting on this matter.
Also, one final note just to point the obvious: trespassing, burglary and other offenses can be considered serious crimes in your area. If you believe you might be committing a felony, you should stop and inform yourself first. I believe no one in here endorses illegal activities. :-)
SECOND EDIT
I understand that laws will be different from country to country, no need to keep telling me that. However, the answers given so far are all quite interesting and what I was looking for, so I will keep the question as is.
Thanks guys.

A:

My general belief is that in the United States entering structures like the ones you've pictured would be considered trespassing regardless of if there is a sign in place or not. This is based on the fact that I'm almost certain that if you become injured while on the premises you could sue the land owner. I believe the trespassing signs are just there to give legal cover to the land owner in case someone does try to sue them.
Here are two sources that essentially support my beliefs:
General definition:

Trespass is defined by the act of knowingly entering another person’s property without permission.

More detailed legal definition:

§ 11.411 Criminal trespass.
(a) A person commits an offense if, knowing that he or she is not licensed or privileged to do so, he or she enters or surreptitiously remains in any building or occupied structure. An offense under this subsection is a misdemeanor if it is committed in a dwelling at night. Otherwise it is a petty misdemeanor.

As you can see these buildings are clearly owned by someone, and you clearly haven't gotten permission to enter the building. Ergo, you're trespassing.
Now if you were talking about ancient Mayan ruins, or an Old West ghost town then this would be more of a gray area, I believe, since those structures have been abandoned for 150+ years. The same goes for structures in National Parks, since a National Park is public land you could make a case that you thought you were allowed to go since you weren't specifically told you can't go (assuming you didn't cross a fence line/no trespassing sign). You should definitely contact a real lawyer though.

Now if you do enter then I think the probability that you will be caught and prosecuted would be fairly low. It is your decision if that risk is worth the reward of entering/exploring the structure.

A:

In the UK, trespass (except in places like nuclear plants and railway lines) is a civil offence not a criminal offence, and so you can only be sued for compensation for any costs the landowner incurred as a result of your trespass, and you can't get a criminal record.

A:

For the most part, if you don't do any damage to the property, or yourself, and don't get caught, then I don't think you've anything to worry about.
As others have mentioned, liability is a property owners primary concern when it comes to vacant, condemned, or abandoned properties. Even if they don't get sued, if someone breaks their neck parkouring on a roof that caves in, then it's a big time hassle just to fill out reports and do investigations, but if you do no harm, then no harm done. 
When I was younger I explored numerous abandoned buildings, including one which was featured in the first Transformers movie (an old train station). I even got caught a couple times, but all that happened was we got kicked out and told not to come back because they didn't want us getting hurt. There were even a number of times when we'd run into other people exploring the same building as us. 
One thing you do want to be cautious of though are vagrants, vagabonds, and mobs. When I was in Philly we were advised to stay out of abandoned buildings because it was not uncommon for gangs to conduct illegal operations in them. People have been shot for stumbling onto hidden drug ops, or knifed by some desperate homeless person for their pocket change. More than once I've ventured into dark rooms omitting suspicious odours, afraid I might find a rotting corpse. One time I did, but it was only a deer (at an old iron mine).
Pro tip: We discovered it was incredibly easy to get away with our escapades if we were dressed in costume. One of the times I got caught was in a skyscraper construction site, I was wearing full body woodland camo and a bandana, the security guard just gave me a puzzled look then directed me towards the gate in the 12ft perimeter fence where he let me out. One of my friends would always dress up as old school batman, cape and everything. The cops just laugh, and let you go, then they have a funny story to tell their pals. Also, if you get caught, just smile, cooperate and play dumb, "This place is so cool! Oh we aren't allowed in here? Okay, sorry, we'll just leave then."

