Some folks do better with pedal systems which offer float. Others do better with no float. Flats can usually be considered no float. So maybe you are allowing your feet to move into positions which unnaturally flex your knees, or maybe you are fixing your feet into a position you don't naturally assume on your flats. So watch and feel exactly how you ride with your flats and try to duplicate that with your clipless.
It's also possible that with the clipless pedals you can now push and pull on your feet in directions not permitted with the flats, and your knees are not used to these muscular stresses. If so, take it easy with them and gradually build up to a proper clipless pedal stroke.
Stretching might be helpful.