Kirkcaldy, William, Sir, Laird of Grange, Captain of Edinburgh Castle