What is the context of James 5:16? What does confessing our sins have in relation to anointing the sick and him being raised up? Is that a commandment from Jesus to confess our sins to each other in any context?
It does appear that James is a bit random in what he is talking about in James 5. What I mean is that some of the specifics he talks about are not obviously directly connected, so I can see why you find this confusing.
The context here is prayer. All the comments James make are related is some way or another to prayer.
In James 5:15 James tells us that our prayers may actually cause God to intervene physically and make a sick person well. We are not just going through the motions when we pray for the sick.
Then, he seems to change subject a bit and says something which is somewhat surprising. He tells us that through our prayer, the one who has sinned may be forgiven. This is a difficult little passage in light of other passages. In the light of other passages, it certainly does not mean that a person is saved by us praying for that person. I believe that the point of James is that when we pray for people, God will hear our prayer and will help those for whom we pray. Our prayer can actually help another person to avoid a particular sin or to have his/her heart softened so that they can repent and be forgiven. It is not that our prayer directly causes God to forgive another (at least as I see it) but the effect will be more indirect.
Moving along to James 5:16, we are commanded to confess our sins to one another. Remember the context is prayer. As we confess to one another, we will be praying for one another, and therefore, as in James 5:15, we will help one another to avoid sin. You ask if this context applies to any context. I am afraid I do not know exactly what you mean by that. My generic response is that we should generally be in the habit of confessing our sins to one another. It is always a good idea to do this (although we might want to use wisdom who we confess to and how we do this). James says that by confessing to one another and praying for one another–especially in the areas where we are struggling with sin, God will help us to stop sinning (5:15) and the result may be physical healing (5:16). Clearly, James makes a connection between our physical and our spiritual health. James then completes the thought in 5:15-16 by telling us that our prayers are powerful and that they have specific and noticeable effects, both spiritually and physically (“our prayers are powerful and effective).
I hope this helps.