I think "idiot" and "dummy" have the same meaning and they both mean someone stupid. But I came across this sentence, "I might be an idiot, but I'm no dummy." and now I'm wondering what's the difference between these two words in a sentence like this.
Although idiot and dummy do commonly have the same meaning, the use of idiot in this joking phrase draws particular attention to a specific sense of idiot.
From Merriam-Webster's definition of idiot:
1 : a foolish or stupid person
It's the use of foolish in the definition that's relevant.
From Merriam-Webster's definition of dummy:
1 c : a stupid person
// He's no dummy.
// She loves you, you dummy.
In short, the sentence in the question is actually saying this:
I might be an idiot, but I'm no dummy.
→ I might be foolish, but I'm not stupid. OR
→ I might act unwisely, but I'm not unintelligent.
Idiot is more formal; dummy is mainly US and informal. They both mean the same thing and each can cover a range of levels of stupidity. The speaker is implying that a 'dummy' is more stupid than an 'idiot', but it could equally have been the other way around. The clue is the 'I might be X but I am not Y' construction, where Y is implied to be more extreme than X, e.g. I might be crazy but I am not a lunatic! 'Crazy and 'a lunatic' could be the other way around and the intended meaning would be the same.
To be noted: nowadays, using terms like 'idiot', 'dummy', 'cretin', etc, to discuss mental or intellectual impairment is considered cruel and deplored by many people in Western societies.
This is clearly a joke or a retort to an insult.
The word "dummy" carries with it the connotation of the verb "dummy" (to trick by pretending to pass a ball), so the additional connotation of dummy, that idiot doesn't have, is "a person who is easy to deceive".
So "I may be an idiot, but I'm no dummy" suggests that the person is saying that he can't be tricked:
If you don't buy this car, you would be an idiot.
I may be an idiot, but I'm no dummy! I can see that the engine is leaking oil. This car would cost too much to repair.
"Dummy" is apparently derived from "dumb", which can mean "stupid", in turn meaning "having or showing a great lack of intelligence or common sense".
"Idiot", although now used as a pejorative term, was once an actual medical term used in psychology for someone deemed to have an IQ between 0-25 ("Imbecile" meant an IQ of 26–50, and "moron" an IQ of 51–70, both of which are also used today as insults).
Of the two insults, "dummy" is the more playful of the two and probably less offensive, although "dumb" was also once used as a term for those unable to speak due to deafness and is now considered insulting or rude in that context, so I would still be careful about using it.
I can't really explain your quote "I may be an idiot but I'm no dummy" without the wider context, but it is most likely a joke, suggesting that the speaker is so stupid they don't know that both words mean stupid.