Several users trying to jailbreak iOS 9.1 beta untethered have reported encountering the Error code 51 as the jailbreak process gets stuck around the 65% mark. The error code description states: "Error occurred in preparing the environment".
It is ascertained that the error occurs due to coding incompatibility issues between the Pangu 9 jailbreak and iOS 9.1 Beta, as the tool was built to support iOS 9 through iOS 9.0.2 versions only. However, folks at Redmond Pie have shared a simple fix to get rid of this error.
How to fix 'Error occurred in preparing the environment, Err Code (51)' during iOS 9 jailbreak
Step 1: Ensure you have synced all your data files via iCloud or iTunes or locally through your computer. However, a full data backup will not help in this situation as backups created with newer iOS versions (iOS 9.1) cannot be used to restore to an earlier version (iOS 9 through iOS 9.0.2).
Step 2: If you are trying to jailbreak the iOS 9.1 public beta build, then you have to remove the beta profile via Settings > General > Profile.
Step 3: Reset all the settings by going to Settings > General > Reset and select Reset all Settings.
Step 4: Download the latest version of iOS (9.0.2) to your computer and perform a clean install on your iOS device, using our step-by-step guide posted here.
Step 6: That's it. Your iOS device should now be jailbroken without any hassles.
[Source: Redmond Pie]