The Player's Handbook says that a spell can be traded at level up for any other spell in any slot that you can cast. I'm wondering if I can trade a spell learned from magical secrets and if the new spell I get from the trade can be from any class. There doesn't seem to be any specific mention in the rules.
Well, there's good news, and there's bad news. The good news is that you can trade away the spells from Magical Secrets. The bad news is that you can only trade them for bard spells.
The rules on trading one of your spells known for another say that:
Additionally, when you gain a level in this class, you can choose one of the bard spells you know and replace it with another spell from the bard spell list, which also must be of a level for which you have spell slots.
So, you can only trade away bard spells for other bard spells. However, Magical Secrets says that:
By 10th level, you have plundered magical knowledge from a wide spectrum of disciplines. Choose two spells from any class, including this one. A spell you choose must be of a level you can cast, as shown on the Bard table, or a cantrip. The chosen spells count as bard spells for you and are included in the number in the Spells Known column of the Bard table. You learn two additional spells from any class at 14th level and again at 18th level.
Since the spells from Magical Secrets count as bard spells for you, you can trade them for other bard spells when you level up. This doesn't change the fact that you can only trade bard spells for other bard spells, though, so the new spells you get from trading will have to be bard spells.
As one final caveat, the spells you chose with Magical Secrets count as bard spells for you, so if you trade one of them away, you can later trade something else away to get it back.
RAW says you can trade out the spell (yay!) but probably only for another Bard spell (boo!).
That's according to this Tweet from Crawford that specifies that since Magical Secrets spells count as Bard spells, you can trade them out when you level up, but only for a spell on the Bard list. Personally however, I think this is a pretty vaguely worded ruling and doesn't really answer the user's question.
That being said, this is a very unfun ruling and this question isn't tagged RAW.
Magical Secrets is one of the most awesome things about Bards, and makes them tremendously powerful. Being able to take any spell from the book means you can do things no other class can do, like grant your high DPR party member an extra attack using Haste while also preventing some terrible spells being cast on them using Counterspell (enhanced even further using Jack of All Trades). Or taking Wish at 18th level and making your DM hate you.
At the same time though, having all the good spells from every class makes the rest of the party pretty jealous. It's bad enough for the PHB Ranger to not get 5th level spells until 17th level, it's even worse when the party Bard can take all but two of your spells you choose the next time you level up.
I've found that the most optimal solution is this: if a Bard wants to replace a spell they learn via Magical Secrets at a lower level, they can only choose a new spell that they would have been able to learn at the level they were at when they chose it.
So if a Lore Bard chose Counterspell and Booming Blade at 6th level using Lore Bard's Additional Magic Secrets feature but later learned Booming Blade through the Magic Initiate feat at 8th level, they would only be able to replace Booming Blade with a spell of 3rd level or lower, because that's the max level they could learn at Level 6. (Shield is a good choice for this by the way)
You can trade spells from magic secrets for another spell from any class. The only thing you have to do is replace 1 secret for another, so your magical secret spell number remains always the same (e.g., at level 10 you have 2 secrets, at level 14 you know 4, and at level 18 you know 6 secrets).