I have never noticed that before, but it sounds quite logical to me considering these points.
The character can look to the outside world giving more freedom to new plot lines.
Less background students make it easier to draw focus on the important characters, especially during class hours, when the seats must be taken.
Maybe just personal preference, but I think it is nicer to have pictures with some contrast (window-landscape on one side, tables on the other), than just a dull matrix of tables.
I noticed this as well and it is not even just about where the student sits. In most cases that I've seen, the camera angle is facing the windows (lunch periods, random talking around a desk, etc.)
My theory is that the windows allow for multiple benefits. First, many shows are not just about the school, so looking out the window can be a bit of a waiting-for-school-to-end-so-we-can-play type thing.
Also, having the window in the background gives much more freedom to set the scene. You can easily notice the current weather (oh look, it's raining) or the season. It can also show foreshadowing events (dark clouds on the horizon).
Another possible reason, it allows for the character to feel more like a loner all by themselves in the back corner. If the character is going to be popular, the back row tends to allow more space for others to stand as opposed to the middle of the classroom.
Besides, looking at the other walls is not very exciting and in the end the show is for entertainment purposes.
Something else to add to the other answers is lighting from the window, at least from those examples. That way you can focus on the art of only the important characters while the other students can have less detail since they're in the dark. Plus, it adds more opportunities for interesting shading and light play.
While backbenchers are common throughout the world, windows seats are similarly favoured by just about everybody in most situations. People want and prefer window seats be they in classrooms, trains, or aeroplanes. In anime, these seats additionally facilitate a few things (some of which have been covered in other answers):
That said, I think that there's a mild case of confirmation bias in the question. There are plenty of anime where the protagonist is not seated by the window. Offhand, I can name Makunouchi Ippo in Hajime no Ippo, most characters in Lucky Star, the characters in Hidamari Sketch, and so on.
I also saw this a lot, it really is a good question. ^_^
In my opinion this happens when they are in a bad mood or lonely. When you see your main character sitting at the corner on the last seat looking at the window, it will transfer you the sorrow and sadness he/she has: you gain their feelings.
I think it is for transferring us their mood.
Another reason could also be that the proximity of the window allows different light settings on the character. A brighter light make the character 'shine' compared to the others that are in the darker part of the room.
This answer was based on a valid criticism of the question in the answer by coleopterist. It does not seek to answer any of the questions posed in the OP, which in my opinion are already satisfactorily answered in several of the other answers, and should ideally be viewed as an extended comment on that answer.
The following are preliminary statistics, based solely on the anime I currently have access to. There is much to criticize, but I believe it is good enough for now. I intend to do a more detailed study of this in the future; please see the Future Work section below.
The goal of this study is to gather statistics to attempt to confirm or invalidate the proposition that anime protagonists disproportionately sit near windows in classrooms. It was also found interesting to consider how far back in the room these characters sat.
In what follows, the term "column" will be used for a line of desks parallel to the window, and "row" will be used to mention lines of desks perpendicular to the window.
Play the first episode of all anime currently available in which the protagonist is a student. There were no cases where the protagonist was not obvious. Attempt to locate the protagonist's seat by playing through the video at 8x normal speed, pausing when necessary. If the protagonist's seat can be located, note it, otherwise mark it as undetermined. In order to save time, multiple videos were played concurrently in many cases.
The 34 anime series I currently have access to in which the protagonist is a student at or below high-school level. This is by no means a representative sample, given that they are disproportionately recent anime. A fairer method will be used in future studies.
Of the 34 anime included, in 18 cases the protagonist's seat could not be determined. In the remaining 16 cases, 7 were next to a window, and 6 of those 7 were in the back two seats of that column. Of the remaining 9, 3 were in the back two seats in some column other than the column closest to the window. 4 were in the front row, and 2 were somewhere else (in one of these cases the classroom had no windows). In most cases, there were 5 or more seats per column, and at least 4 columns. It was not uncommon for one or more other significant characters to be seated in the immediate vicinity of the protagonist, and the reason that the back two seats were counted rather than just the back one was specifically for the cases where another character is sitting directly behind the protagonist.
It appears that both being near the window and being towards the back of the classroom are both disproportionately common based on this limited sample. These accounted for, respectively, 7/16 (43.8%) and 9/16 (56.3%), while the expected rate for both of these for random data would be well below 50%, especially in the former case. The results are not very significant statistically, suggesting that more data is in order.
There are issues with the methodology which merit further work. In particular, the sample is by no means representative. It is prone to my own biases, which aren't easily measurable, so a more controlled experiment is needed. Rather than a self-selected sample, a better to choose a representative sample in some way which is less biased. Possible options include looking at a list of most popular anime or all recent TV anime. Either of these is expected to increase the amount of time required. The various merits and issues with each of these options will be weighed.
Another issue is that the first episode may not be sufficient. It would be good to go through enough of each anime to be sure that the correct seat is chosen, though this may prove difficult. Whatever method is used, it must be unbiased to avoid confirmation bias. This is expected to increase the time required for future studies.
A third issue is that the sample sizes are insufficient for detailed study, or even to make any real conclusions extending beyond the sample itself. In some sense this is a fundamental issue, as it will always be time consuming to locate the seat of any character in anime. Even a sample size of 34 took a significant amount of time, and the modifications in the above paragraphs are likely to increase that significantly. A sample size of 100 seems like the largest practically feasible number. The considerations of this paragraph and the above two will need to be balanced against the time of the study, which is expected to be significant (indeed, even this preliminary study proved more time-consuming than I would have liked).
While the primary goal of future studies should be establishing to a higher degree of accuracy whether this effect is truly present (and if so how large of an effect it is), there are other interesting things to look at in the long term. A few are presented here:
Correlations between the seat choice and the genre would be interesting to look at, but are likely to require significantly more statistics than are feasible. This is mentioned as a possible long-term project, but it's unlikely to be completed. The more pressing goal. In addition, it would be interesting to do a similar study for other media, but this is likely to be less trivial as most other media are less uniform in presentation than anime. Finally, a historical survey, studying how common this was in different periods, would be very interesting but is probably too ambitious.
tl;dr: Yes, this does seem to be a real thing, at least preliminarily. It's certainly not always the case, but it happens frequently enough to be interesting. However, the data I have aren't good enough to make any solid conclusions beyond "yes, this happens more often than one would expect". More data will be needed to determine to what degree this is due to biases and statistical variation in the sample, and to what degree this actually happens.
Can't answer for the reasoning behind this trope.
But it seems pretty frequent, so much that BlogSuki's Jason calls it the First Modern Law of Anime:
“All major characters will have their desk window side towards the back. Sub Law: If a romantic interest occupy the same classroom, that character would be within one desk of this desk.”
(the sub law seems to work with rivals too)
The visual aids that windows provide are to highlight a character. They do so either by special illumination or attracting the eyes: objects placed next to bright windows tend to get noticed first.
Scene bottom-left: Light Yagami is highlighted by being illuminated sharply, the other two (convieniently!) have postures that avert their bodies from illumination. Here the illumination is used exclusively, no red laser eyes, fang-baring grins or dramatic name-writing are involved.
Scene top-left: Tomoko is in color and is illuminated not by one, but two beams of light.
Scene top-right: Three individuals get noticed by being close to the viewer and being in an illuminated area.
Scene bottom-right: Tenma attracts attention first by being next to a featureless glowing window and having the most discernible face.
Also, looking out of windows signifies contemplative moods. If my teachers noticed me daydreaming, they would seat me in the front of the class. Japanese school teachers do a poor job of catching students contemplating bloodbaths at the back of their classes.
Would love to see a scene that goes contrary to both explanations.
Rather than looking at the scene to try and find metaphorical reasons for this phenomenon, I suggest a possible financial reason.
It's cheaper to re-use stock background and animation. All anime studios will have cells or digital information from previous anime that are available to them. Rather than re-inventing the wheel for possibly dozens of anime series that they carry they re-use parts some parts that have common themes and then touch them up to add "uniqueness" to the setting.
Not saying this is the case, but considering how most anime high schools look exactly the same, it'd be a safe bet to say this is the reason.