Even though the prescription in your two glasses may be the same, there are several other features of the eyeglass pairs that might be different and that might be causing headaches. For example, it is fairly common to have a pair of glasses that doesn't fit very well. If the arms of the glasses exert pressure on your temples and over your ears, this might cause a tension-like headache
that would obviously go away pretty quickly on switching back to the more comfortable pair of glasses. Also, if the shape of the lenses is different, this might cause the problem. Small lenses have less peripheral vision which might lead to eye strain.
Luckily, this is not a serious problem, as you don't have any symptoms at all when you are wearing the one pair of glasses. What you could do is return to the place where you purchased the glasses and explain what is going on. One of the technicians there should be able to determine if the second pair of glasses fits you well. If not, you will have to change the style of frames to one which is more comfortable for you.