Detach Type Cover completely, wait 10 seconds, and firmly reattach it until you hear/feel the magnetic click. Make sure the connector pins are clean and lined up properly.
Both on the Type Cover and on the Surface body — dust or debris on the magnetic connector pins can break the connection. Use a dry, lint-free cloth or a soft brush.
Download the Surface Diagnostic Toolkit from Microsoft's site and run it — it specifically tests the Type Cover connection and can catch hardware faults.