The Headmaster's upper study can be found at the very top of "The Grand Staircase" with the closest Floo Flame being the "Trophy Room".
Before we can enter the Study we'll need to unlock the Alohomora spell
and upgrade it to open level 3 locks. You'll get Alohomora when you complete the main story quest "The Cartaker's Lunar Lament"
for Caretaker Gladwin Moon - this will allow you to open level 1 locks. After that Gladwin will give you a side-quest "The Man Behind The Moons"
asking you to collect 9 then a further 13 Demiguise Moons. Completing both these side-quest (22x Moons) will reward you with the ability to open level 2 & 3 locks. See my video guide below for all 30 locations. Now we can head to the Headmaster's study!
Travel to "Hogwarts > The Bell Tower Wing > Flying Class Lawn", equip your Broom (
) and fly up towards the Grand Tower. As you move around to the back side of it, you should see a small balcony that you can dismount onto. Fly over the lowest part of the balcony to avoid the invisible wall. From here open the level 3 lock and enter the Headmaster's Upper Study.
Progress through the main story until you've completed "Poly Juice Plot". Now you can Climb to the very top of "The Grand Staircase" until you reach the "Trophy Room" here you won't be able to get any higher until you've open a level 1 locked door. Once open continue up the stairs until you reach a junction, take the left and you'll reach a level 2 locked door. Open this and head out onto the balcony and you'll meet a level 3 locked door. Opening this door will give you access to the Headmaster's Study.