Metals are conductors of electricity,and as known conductors have free electrons.Each electron acts as a bar magnet and it has a north and a south pole.When we put the metal next to magnet,the tiny magnets(free electrons)all line up in a certain way that they are attracted to the magnet.For example,if I approach the south pole of a magnet to a piece of iron,the tiny magnets(free electrons) in the iron piece will line up where all the north poles face the south pole of my magnet.And unlike polarities attract.
Something to know:If you want to know why electrons behave like tiny magnets you might ask why they are charged in the first place .Actually no one knows!.