On some cars and trucks there is an oil pressure sensor that will alert the computer in the vehicle to low oil pressure.
In that case your engine oil light will usually come on and if the oil pressure gets too low or your oil level gets too low then it can shut the vehicles engine off.
The reason that the engine will shut down when it has low oil pressure is to prevent engine damage because when the engine doesn't have enough oil or enough oil pressure the engine cannot be lubricated properly which is bad for the engine.
Eventually the engine could seize and then you'd need to rebuild the engine or replace the engine.
So if your oil light comes on and your engine shuts off you should check the engine oil and if it's low add some oil to it.
If the engine oil pressure remains low then it could be a bad engine oil pump or you have a clogged oil filter.