Without knowing what kind of tablet you have or how old it is, it sounds like a definite hardware issue. If you just purchased it, I would try and exchange it for a new one. If it is under warranty, contact the manufacturer and see if they will do a warranty exchange.
Beyond that, we would need to know the manufacturer and model to see if there is a repair guide where you may be able to locate and fix what is likely a loose wire / connection.