Madrid has apologized for a violent police crackdown on Catalonia's independence referendum.