This is a common pitfall of Array.create. Use Array.init instead when your array element is boxed.
Array.create initializes the array elements with the same value: if the value is boxed, with the same pointer. In your case, all the elements a.(i)
points to the same array created by Array.create 5 0
.
Correct code should be
let a = Array.init 5 (fun _ -> Array.create 5 0)
This creates 5 individual arrays.
You should check this Q/A: Ocaml - Accessing components in an array of records