He scared him because Jim thought that Huck was a ghost.
Mississippi
Jim and Huck were trying to reach Cairo, Illinois so that Jim could attempt to escape to the free states and gain his freedom.
Jim is initially startled when he sees Huck on the island, as he believes that he has seen a ghost. However, he quickly realizes that Huck is alive and is relieved to be reunited with him. Jim is happy to see Huck safe and well.
In the dense fog on the river, Huck and Jim miss their exit and end up floating past it, losing their way in the river's intricate twists and turns. They become disoriented and can't find their way back. Jim and Huck were trying to reach the city of Cairo in Illinois so Jim could get to the free states and be a free man.
Huck doesn't turn Jim in because Jim in Huck's first TRUE friend. Jim is also the only "family" Huck has ever had that cares so much about him and will protect him.
Huck and Jim go to Cairo in hopes of reaching a free state where Jim can gain his freedom. Cairo is near the northern border of a free state, making it a crucial waypoint in their journey to escape the bonds of slavery.
Jim demonstrates frequent kindness to Huck in "Huckleberry Finn" by protecting him, comforting him, and offering him guidance throughout their adventures. Jim always looks out for Huck's well-being, even when faced with personal risks and challenges.
I've only read the book a couple of time, but I think that Jim taught Huck that some adults don't leave. Through their journeys, Jim is constantly supportive and caring and loyal to Huck, who in turn becomes so to Jim. Jim shows Huck how true humanity should be, which is ironic because Jim is considered sub-human by all the members of "The Quality."
Huck and Tom devise a plan involving a pretend escape for Jim, which ultimately results in Jim's actual freedom. They create an elaborate scheme to free Jim quickly by pretending to be robbers and creating a chaotic situation where they can help Jim escape. Through their trickery and quick thinking, they are able to achieve their goal without waiting thirty-seven years.
Jim and Huck originally plan to go to the free states up north to escape slavery and the societal expectations placed on them in the South.
Huck is upset when Jim is sold because he has grown close to Jim throughout their journey, seeing him as a friend and even a father figure. Huck also feels guilty for not coming forward to reveal that Jim is a free man, as he promised to keep Jim's escape a secret.
He had not turned Jim over to the two men looking for runaway slaves.