This happens if you flash the wrong variant of GApps. Ensure you selected ARM , Android 7.1 , and either Pico or Nano layout options.

Flashing custom firmware wipes everything. Use Samsung Smart Switch or manually copy photos, documents, and videos to your PC or an SD card.

to prevent it from shutting down during the flashing process. Available Android 7.1.2 ROM Options Developers on forums like XDA Developers