This is called syncope. Syncope is a temporary loss of consciousness, commonly referred to as fainting, or passing out. It is a fairly common event.
It can be caused by many factors such as cardiac problems, neurological problems, vasomotor, orthostatic hypotension etc. You need to go to a neurologist as well as a cardiologist for assessment.