Finally! I got it!!! The issue was caused by Laravel’s event dispatcher, which was accumulating event listeners during batch inserts, leading to memory exhaustion. The fix was simply to disable the event dispatcher:
DB::connection()->unsetEventDispatcher();