This is honestly a tricky one to figure out. Here's the best explanation I can offer:
The use of "when" is the reason why "am leaving" is unnatural. We could structure the sentence as two independent clauses, and it would be perfectly acceptable:
I am leaving London next month, and I will have studied here for almost a year.
But "am leaving" becomes unnatural when we use it inside a subordinate clause with "when". The simplest way I can make sense of this is that there are a couple different types of subordinating conjunctions, and they like to use different tenses to express future events:
- The first group is time-related conjunctions, like when, once, before, after. Subordinate clauses using these have a bias for the simple present tense. It's natural to say, "When I leave London... once I arrive in New York... before I go to the hotel... after I eat dinner". The pattern here is that these refer to what's happening at a specific moment in time. (The action in every case does take time to complete, but that's not grammatically meaningful here.)
- The second group consists of what I'm going to call "logic-related conjunctions" (maybe there's a more formal term... I don't know). These include because, hence, therefore, and so on. These have a bias for the present continuous tense: "Because I am leaving London next month, I can't come to your wedding in July", or "I got a job in New York, therefore I am leaving London".
- There are also some conjunctions that can go either way... sometimes adding different shades of meaning: as, unless, while, since. Interestingly, most of these words can have time meanings or logical meanings. So, we might say, "I'll wave goodbye as I board the plane," (time meaning = simple present), and also say, "I can't come to your wedding, as I'm moving to New York." (logical meaning = present continuous).
The big exception to the first group (time-related conjunctions) is when you're deliberately referring to something happening during an event. Here the present continuous is appropriate. For example:
When I am writing my thesis next month, I won't have time for Netflix.