How trying it is, when one cannot be president, to be Secretary of State to one so undeserving.
Buchanan's mission to Russia turned out quite well for him. Because Russia had recently enslaved the Poles, and were frightfully unpopular in continental Europe, they decided to fete the American, in order to win an ally. So Buchanan went to all the balls and danced with the Empress and was all around a success. He also managed to negotiate a mutually beneficial trade agreement between the US and Russia, despite (or because of) the fact that the Russians opened all his mail.
So he had left America a b-list politician and returned a statesman. He returned to the Senate for a while, and was a frontrunner for the 1844 presidential nomination. But Van Buren was running, obviously, and he didn't want to openly oppose the party patriarch, pledging only to run if VB dropped out. By the time VB did, Polk was the nominee.
Polk named him Secretary of State, which in any other administration was an invitation to succeed him in office. But Polk was tired of seeing the last year of an administration turn into a squabble over who in the cabinet would be the next president, so he made Buchanan promise that if he planned to run for president in '48, he would immediately resign the State Department. Buchanan kind of agreed, but claimed that if his supporters started campaigning for him, he could hardly be asked to stop them.
Much to JB's chagrin, Polk really only wanted him to manage State, not run it. Polk, you may remember, was a micro-manager. A lot of previous presidents gave the State Department to their bestie so they could work closely together. Since Polk didn't have any friends, he gave it to an able statesman, but didn't let him do anything.
Let's remind ourselves, though, that Polk was an insanely efficient president, and Buchanan was known for kind of writing a lot of letters and never getting anything done. So when Polk wanted to settle the Oregon/Canada border he was like "Tell the British 49 degress" and Buchanan was like "They'll never agree" and Polk was like "I'll just do it" and Buchanan was like "Surely we should send another envoy to talk to them about it" and Polk was like "Nope!" and Buchanan was like "We need to have more meetings about this" and Polk was like "I just did it while you were fussing." So, they were not a match made in heaven.
When a Supreme Court position opened during Polk's presidency he offered it to Buchanan, probably to be like, get out of my life, but Buchanan turned it down and suggested a friend of his. Polk ignored his suggestion and nominated somebody else. Once the nomination was up for confirmation, Buchanan was like "Well if you're going to ignore my suggestion than I'll go ahead and take the post" and Polk was like, dude, they are already voting on it. The nominee was not confirmed, so Buchanan kindly informed Polk that he would take it. This time Polk just ignored him and nominated somebody else, who was confirmed, and then Buchanan was like "Yeah I don't want it" and Polk was like DUDE.
Buchanan was basically peeved that he was the most reined-in Secretary of State in American history, which is fair enough. It meant that all the prestige that usually comes from holding that post, which so frequently translates into a successive presidency, was denied him, because everyone in Washington knew he didn't do anything.