The Scottish FA will be staying at Hampden Park after agreeing to buy the national stadium from Queen's Park.