It's a shortened version of "Robert Peel", the British Home Secretary who established the Metropolitan Police in London in 1829. The officers of this new force were initially referred to as "Peelers" or "Bobbies" in his honor.
Over time, "bobby" became the more popular term and spread to refer to police officers throughout the UK.