How is the triangle vertex data of BVH arranged in memory?

I have found that arranging the triangles more closely together reduces the time of BVH traversal, why is this?

Please explain what you mean with “arranging the triangles more closely together” in absolute coordinates.
Maybe draw some schematic picture.
About how many built-in triangles are we talking?
What is the absolute performance difference you see on what system configuration?

Because of the increased spatial locality?

The BVH traversal time depends on how many AABBs the traversal needs to check for intersection.
The more AABBs can be trivially rejected, the faster the actual intersections get determined.
This depends on your scene structure, the BVH builders, and the rays you shoot.

And I want to know how is the triangle vertex data of BVH arranged in memory?

How the BVH builders work exactly is confidential information and changes with GPU architectures and even driver releases.

OptiX has some flags which influence how the acceleration structure is built.
Specifically OPTIX_BUILD_FLAG_PREFER_FAST_TRACE and OPTIX_BUILD_FLAG_PREFER_FAST_BUILD
Described here: https://raytracing-docs.nvidia.com/optix8/guide/index.html#acceleration_structures#build-flags
and the OPTIX_GEOMETRY_FLAG_REQUIRE_SINGLE_ANYHIT_CALL
Described here: https://raytracing-docs.nvidia.com/optix8/guide/index.html#acceleration_structures#6101

Then there is acceleration structure compaction which will improve memory locality of the final AS data.

Also there is the OPTIX_BUILD_FLAG_ALLOW_RANDOM_VERTEX_ACCESS flag which allows to read vertex positions from the AS which can affect performance negatively.
https://raytracing-docs.nvidia.com/optix8/guide/index.html#device_side_functions#vertex-random-access

Is it arranged according to spatial location or just according to the BVH structure?

The BVH structure depends on the spatial location of the primitives and their sizes.

Slightly related topics of how bad spatial scene structures can affect performance:
Bad grouping of GAS contents under IAS: https://forums.developer.nvidia.com/t/bvh-building-algorithm-and-primitive-order/182231/2
AS refit instead of rebuild: https://forums.developer.nvidia.com/t/updating-as-leads-to-extremely-low-traversal-performance/267416/7

Also this isn’t the first time you asked about this and the answers won’t change.
https://forums.developer.nvidia.com/t/decomposing-bvh-to-accelerate-traversal/283911/2
https://forums.developer.nvidia.com/t/how-to-speed-up-the-traversal-speed-of-bvh/256481/2