There's a lot of scope for confusion over this (British English) usage for the word guard, which isn't necessarily resolved by saying...
BrE guard = AmE conductor
a railway train crew member responsible for operational and safety duties that do not involve actual operation of the train.
(another AmE definition, from the Railroad Jobs Guide)
Railroad conductors examine schedules, switching orders, bill of ladings, and shipping records. On passenger trains they are responsible for the passengers and crew.
I'm not sure there is an AmE equivalent to BrE guard in this context. Essentially, all uniformed railway staff in the UK may be called guards - except when they're actually working on a train, in which case they're usually called ticket inspectors or sometimes conductors (or drivers, where appropriate, obviously!).
In OP's context, neither Harry (the fictional character) nor JK Rowling (the British author) would know or care exactly what job title the "guard" was actually employed as. So far as they're concerned, he's just any uniformed employee that passengers can reasonably treat as a representative of the company, when asking a simple railway-related question such as "Where can I find the train to Hogwarts?".
TL;DR: BrE guard approximately corresponds to AmE railroad conductor. There's no special implication that any specific guard has any security-related duties, but obviously some do.
;)