I have been asked why 'I am' is changed to 'am I' in the second sentence. Which is the grammar rule that says the order has to be reversed that way?Who am I speaking to?
May I know who I am (not 'am I') speaking to?
In indirect speech we do not normally use direct question word order,
The question mark in your example goes with the direct question 'May I know....', not with the indirect question.