Is it legal? Well, I'm not aware of any statute that states it is specifically legal to do so. Rather, there is a statute (below in blue) in place that states it is Illegal to alter coinage in a fraudulent manner. From 1965 to 1969 there were regulations in place that prohibited the melting of US silver coins but when that expired refiners were able to melt the coins.
Section 331 of Title 18 of the United States code provides criminal penalties for anyone who fraudulently alters, defaces, mutilates impairs, diminishes, falsifies, scales, or lightens any of the coins coined at the Mints of the United States. This statute means that you may be violating the law if you change the appearance of the coin and fraudulently represent it to be other than the altered coin that it is. As a matter of policy, the Mint does not promote coloring, plating or altering U.S. coinage: however, there are no sanctions against such activity absent fraudulent intent.
Conversely, in respect to the One Cent and Five Cent coins, there was a law written in late 2006 that bans melting them or exporting large sums of them.
This information applies to US Coins. I'm not aware of any statutes concerning the melting of foreign coinage.