When you shoot a building and ur sensor surface is not parallel to the building surface you end up with such tapering ends. The more you tilt up to shoot the more tapering it gets.
You can use a perspective control / PC lens ( it is the shift that helps ).
Advantage being you can visualise the borders of the shot taken after correction on the lens.
The other option is to use Photoshop like what the others have mentioned. However to make a geometrically correct correction takes abit of effort as well, and you will have to crop abit of picture elements post correction.
there are 4 things you can correct, if THEY ARE NOT TOO EXTREME in the picture
in this order:
1) lens distortion (usually for wide angle, barrel is a problem).. search for barrel distortion correction to understand what this is. if you shoot scenes regularly with the same lens, as most people do, just remember the amount of correction to apply and you should be fine.
2) horizon levelling - make sure your horizon, if present is STRAIGHT first, don't use vertical edges.. horizons have to be far far away. when no horizon, use far away objects vertical to make sure this is straight. this is done using free rotation.
3) THEN do vertical perspective correction, if your verticals are not straight (don't assume, check first).. this is the one described in the link gien by giantcanopy, KRW tag. this is because you are looking up or down instead of camera back being parallel to the vertical. if not sure what i mean, go close to a wall or pillar, and look up and down, see whether the vertical is coming towards you, or away from you, therefore appearing tilted in 2d context, instead of being vertical.
4) lastly, horizontal perspective correction, not as common, usually can skip. due to wideness of scene, and say, got object running horizontal and meant to be parallel to horizon but is nearer and therefore at an angle, does not appear straight, something like vertical perspective problem..
1,3,4 done with lens distortion filteri n photoshop
if you use a spirit level properly, usually 2,3 eliminated.. 1 will be present no matter what, and is optional to correct in such a case since will not be too obvious, 4 is rare. why you should use a spirit level.
if you still don't understand, just note the terms i have mentioned, and: