Guards are high level characters that try to preserve the peace in the city in which they are at. They will ask you if you would like to go to jail, pay off your crime, or resist arrest if you commit a crime. If the bounty on your head is too high they will not give you these options and attack you on site. If you resist arrest they will attack you also. You can get your bounty removed if you talk to certain people in the Thieves Guild.