A gunman opened fire in a "targeted attack" on a newspaper office in Maryland's capital, killing five people and wounding others before being taken into custody, police said.