The story
Phonetic alteration of m'lord. As an interjection, playing on the perceived elderly and upper-class nature of judges, and the urban legend that a barrister once had to explain The Beatles to a judge as "a popular beat combo, m'lud".
Etymology from Wiktionary, CC BY-SA 4.0.