Is 你好，北京 grammatical?
Both are correct!!
你好，北京 is more like a casual greeting, e.g. Hello World! :D
北京，你好 is more like a greeting with a touch of respect, because you address the name first. Examples are, 张老师，你好 (Teacher Zhang, hello).