Say I find a spell like Detect Magic in a spell-book and want to learn it. Due to the fact that the spell has no material component, and the only reason spells cost anything is because your using materials to practice with them, would it cost anything? I can't think of what kind of material someone would be practicing with. Even if someone was testing the spell on something magical it's not like once they use the spell their magic item just disappears. So to summarize what I just said I'm wondering if a spell without a material component costs gp to learn.
Yes, all spells cost gold to learn.
Copying a Spell into the Book
When you find a wizard spell of 1st level or higher, you can add it to your spellbook if it is of a level for which you have spell slots and if you can spare the time to decipher and copy it.
For each level of the spell, the process takes 2 hours and costs 50gp. The costs represents material components you expend as you experiment with the spell to master it, as well as the fine inks you need to record it. Once you have spent this time and money, you can prepare the spell just like your other spells.
That's a fixed cost - it doesn't matter whether the spell has a material component, no material component, or even an expensive material component. All spells cost 50 gp x spell level to learn.
It depends a bit on what you mean by "learn it". The only spellcasters with spell books are wizards, those who have the Ritual Casting feat, or warlocks with the Book of Ancient Secrets invocation. All of those require 2 hours and 50gp/level of spell to afford the rare inks, etc., to add a spell to their book. So those all would be 50gp to "learn", for Detect Magic.
For anyone who "learns" spells by fixing them in their head (bard, eldritch knight, arcane trickster, ranger, sorcerer, warlock), and is in the process of going up a level, which gives him the ability to add a spell and/or change a known spell, you could do that without cost (if that spell is on your spell list), as no costs are mentioned for learning spells for any of those classes.