In The Hobbit, Bilbo's conduct with regard to the Arkenstone is most open to criticism when he first discovers it and hides it, knowing quite well that Thorin is desperately searching for his lost heirloom. However, it may be that even at this stage, he has some idea of how Thorin will eventually behave towards the Wood-elves and the men of Lake-town.
With this slight caveat, it seems reasonable to say that Bilbo's conduct was correct and, indeed, selfless, brave, and noble. The only person who seriously disapproves is Thorin, who is not only self-interested but, at this stage in the narrative, has become crazed with greed. Bard and the Elvenking are both impressed by Bilbo's sacrifice. Crucially, so is Gandalf, who is the closest thing the story has to a moral center.
Throughout The Hobbit and The Lord of the Rings, Tolkien champions the values of the Shire. The hobbits of the Shire are prosperous and, in some ways, materialistic, but none of them is wealthy or important enough to possess such a thing as the Arkenstone. The fact that Bilbo finds this beautiful object easy to give up, and the way in which he sees it primarily as a way of doing justice and avoiding conflict, shows that he is an unusually sane and decent character, a true citizen of the Shire. This is why he survives for so long as custodian of the ring.