Work-related deaths for firemen and cops were not uncommon, and when one or more of these deaths would occur, the Irish community would hold a traditional Irish funeral, including the mournful bagpipes. Over the years, this tradition spread to firefighters and police officers who were not of Irish descent.
So if it's an Irish tradition, why are the Scottish bagpipes used?
In short, it's because the Scottish highland bagpipes are significantly louder than the traditional Irish uillean pipes. Though it's likely that either or both types of pipes were used at funerals in the 1800s, the Scottish highland pipes are now almost universally used.
Where do they find bagpipers to play at firefighter and police officer's funerals?
Fire and police departments in most major cities have a special brigade, usually as a division of an Irish fraternal group called The Emerald Society, who learn to play bagpipes and drums for the very purpose of honoring their fallen comrades. In some places, civilians may be members of the pipe and drum band, but generally, the members are active or retired firefighters and police officers.