How does a cpap machine cure me from apnea? Please someone explain to me how by putting this machine, my brain learn to send orders to breath?

Airway obstruction. Obstructive sleep apnea is caused by upper airway obstruction, from tonsils or other soft tissues in the back of the throat closing off the airway. CPAP keeps the pressure up in your upper airways, thus not allowing those tissues to collapse, similar to a partially inflated balloon. This allows you to breathe normally when you sleep.
No orders. CPAP does not order the brain to start breathing. Think of CPAP as sticking your head out of the window of a moving car and breathing.. It forces air into your wind pipe. CPAP machines, though, are very sophisticated. They can be set to delivery just enough air to keep your airway open to prevent collapse.
Keeps airway open. It will not cure your apnea, meaning that most likely always you will have to use it unless you modify some factors contributing to it such as extreme obesity etc. CPAP helps to keep your airways open, therefore it is easier to breath. It will prevent periods of low oxygen levels in blood and brain, so it will decrease headaches, tiredness and progressive dementia from low oxygen levels in brain.