I am a physician, starting as a Family Practitioner and switching to Emergency Medicine. I can safely say that over the decades, I've examined and done procedures of some kind, including suturing lacerations, removing foreign objects from ear canals and other invasive and unpleasant things on thousands of children ranging from infants to... lets limit it to 10 year olds. Having said that, I'll limit this to my experience with 2 year olds, so hundreds. You (and others) will most likely not like my answer.
Would it normally be expected for a (almost exactly) two year old to be able to lie still for several minutes on command, even in an unfamiliar situation such as being covered in electrodes in a doctor's office?
In my experience, yes, a 2 year old should be - and (vastly) most commonly is - able to lie still for an invasive or semi-invasive procedure for a stranger in the presence of one or both parents, including ECGs (which don't hurt). If the parents act respectfully towards the physician in the presence of the child, the child most commonly understands there is an unspoken transfer of authority to the doctor, and having no experience with this adult, do not try to "test boundaries"; IOW, they tend to unquestioningly obey the physician.
Kids of different ages have differing fears and ability to control themselves based on their ability to anticipate discomfort. I would expect a 2 year old to be wary of strangers, but acquiescent in the presence of a calm, encouraging and supportive parent.
Having said that, it sounds like your physician did not have a bedside manner very suitable for your child. It's much, much easier to have a cooperative patient if the child is approached with patience and respect. Once a child is afraid of the physician and has lost trust in them, it's very much an uphill battle. One I have very rarely fought (thankfully.)
If it is expected, what techniques could we use to help our daughter to learn to do this at her age?
It's not your job to teach your 2 year old how to behave during a procedure. It's the doctor's job - or the technician's - to know how to put apprehensive patients at relative ease and gain their cooperation. Sure, if you had electrodes at home to play with ahead of time, it could be helpful, but pulling the electrodes off improperly could be uncomfortable enough to make it more difficult, not less, for the person doing the real EKG. So I would not recommend it. Gaining their trust takes time, and unfortunately, doctors have less and less time to spend with patients every year. This is clearly suboptimal for both the doctor and the patient.
So, your doctor made one correct statement and one I would consider incorrect. Furthermore, they were inappropriate in their failure to control their frustration and lashing out.
I'm not a pediatrician, but as a family doc, I learned lots of tricks for dealing with kids from my teachers in med school and residency, and added my own to my repertoire. In this case, I would have started by showing the child an electrode and letting them handle it. ("See? It's only plastic, and it's a little bit cold. But we can warm them up like this, see?") I would have reassured them that it doesn't hurt, would have applied one to the parent's arm and asked the parent if it hurt. If that wasn't enough (it usually was), I would ask the child if they would let me do it if we did it to their parent at the same time. That's usually acceptable. If not, I would offer to do it to myself at the same time, or before (to show them what it involves.) Sometimes silliness works. Seriously, I've never had to go further than this, but for painful procedures, I would resort to bribery: stickers, ice cream, or whatever floated their little boats (asking the parent, of course). If a child had to be held down against their will (which of course doesn't allow for an accurate ECG), I would have considered it a failure on my part, unless and only unless the parent was inappropriate and frightened the child themselves, which, believe it or not, happens.