The reasons for checking your passport vary. The checkin staff are doing two things: confirming you are indeed the person named on your ticket, and confirming (with the help of their computerized system) that you will be allowed to make your journey. They do this because if you are not allowed into your destination country, or to make a transit, their airline will have to pay to return you to your starting point or your home country. They are trying to avoid that expense by checking your status.
Just before security, in many US airports, your passport is again checked to make sure you personally (as in the person who matches the picture) are allowed into the secure area that is for passengers only. You can of course forge a web checkin style boarding pass easily enough, so they also sometimes scan your boarding pass to check with some other system that someone with your name really is on that flight today. This check doesn't care about your immigration status, just that you really are a passenger. They may ask you some questions, just to see how you react. If so, they choose questions people expect to be asked in airports like "Where are you headed today?" As well, in many airports they are making sure you're in the right terminal or line - I once lined up for domestic security and had to be told to head over to a different line for international security. That's not checking your visa, even if the questions seem similar.
In many European airports there is an exit immigration check. Here they are not so much checking as they are recording. They swipe your passport not so they can look you up in the system, but to tell the system you have left. You may find it difficult to leave the airport should you change your mind about flying after you've been marked as having left.
At the gate, some people have not yet been checked by the airline to ensure they are able to fly. These people typically check in online and don't check luggage, so they can just head for the gate without interacting with airline staff. The security and exit checks were not to serve any purpose of the airline (saving them the cost of bringing you back) and do not pass information about you back to the airline. The gate staff page these people, look at their passports, and do something involving their computer system that is the same as what would have happened if the people had already interacted with airline staff.
As you actually board, the airline staff again look at your passport and your picture, this time ensuring that the person they are letting onto the plane is the person who bought the ticket and whose immigration status has been so carefully checked. Imagine you are allowed into country A but not B, and you want to go to B. You could buy a ticket to A, and get a friend to buy a ticket to B, both check in and get boarding passes, and at the last minute you use your friend's boarding pass to go to B while your friend either goes to A or cancels at the last minute. That would cost the airline to send you back when you weren't allowed into B, so they check again one more time.
It doesn't stop there. Sometimes there is a passport check on the jetway as you leave the plane. I am not really clear why but I think it is to ensure people from different flights don't meet and exchange documents. Imagine again you are not allowed into B but have somehow managed to get there. If a friend who is allowed into B can land there at the same time as you and pass you a passport, you can get into B using it and the friend can either be deported (maybe they don't mind) or can say they lost their passport and get let in using some other ID. (This seems kind of pointless when the friend could mail you the passport in advance and you could use one to board and one to land, but I don't know why else they do these jetway checks.)
It's frustrating, because you think your passport is conveying the same information every time. But it's not. It's always confirming who you are, and most of the time it is not being used to confirm you're allowed to enter the country you're going to.