A popular argument focuses on the deaths of "innocents" in judgment, especially in the OT. Some of these are answered with proper focus on survival and values in the ancient world (as in the case of the Amalekites -- see link 1 below), but one story we will focus on here -- the sin of Achan in Joshua 7 -- is to be treated differently.
To set the context, here are the relevant passages:
Joshua 7:1 But the children of Israel committed a trespass in the accursed thing: for Achan, the son of Carmi, the son of Zabdi, the son of Zerah, of the tribe of Judah, took of the accursed thing: and the anger of the LORD was kindled against the children of Israel. 2 And Joshua sent men from Jericho to Ai, which is beside Bethaven, on the east side of Bethel, and spake unto them, saying, Go up and view the country. And the men went up and viewed Ai. 3 And they returned to Joshua, and said unto him, Let not all the people go up; but let about two or three thousand men go up and smite Ai; and make not all the people to labour thither; for they are but few. 4 So there went up thither of the people about three thousand men: and they fled before the men of Ai. 5 And the men of Ai smote of them about thirty and six men: for they chased them from before the gate even unto Shebarim, and smote them in the going down: wherefore the hearts of the people melted, and became as water. 6 And Joshua rent his clothes, and fell to the earth upon his face before the ark of the LORD until the eventide, he and the elders of Israel, and put dust upon their heads. 7 And Joshua said, Alas, O Lord GOD, wherefore hast thou at all brought this people over Jordan, to deliver us into the hand of the Amorites, to destroy us? would to God we had been content, and dwelt on the other side Jordan! 8 O Lord, what shall I say, when Israel turneth their backs before their enemies! 9 For the Canaanites and all the inhabitants of the land shall hear of it, and shall environ us round, and cut off our name from the earth: and what wilt thou do unto thy great name? 10 And the LORD said unto Joshua, Get thee up; wherefore liest thou thus upon thy face? 11 Israel hath sinned, and they have also transgressed my covenant which I commanded them: for they have even taken of the accursed thing, and have also stolen, and dissembled also, and they have put it even among their own stuff. 12 Therefore the children of Israel could not stand before their enemies, but turned their backs before their enemies, because they were accursed: neither will I be with you any more, except ye destroy the accursed from among you. 13 Up, sanctify the people, and say, Sanctify yourselves against tomorrow: for thus saith the LORD God of Israel, There is an accursed thing in the midst of thee, O Israel: thou canst not stand before thine enemies, until ye take away the accursed thing from among you. 14 In the morning therefore ye shall be brought according to your tribes: and it shall be, that the tribe which the LORD taketh shall come according to the families thereof; and the family which the LORD shall take shall come by households; and the household which the LORD shall take shall come man by man. 15 And it shall be, that he that is taken with the accursed thing shall be burnt with fire, he and all that he hath: because he hath transgressed the covenant of the LORD, and because he hath wrought folly in Israel. 16 So Joshua rose up early in the morning, and brought Israel by their tribes; and the tribe of Judah was taken: 17 And he brought the family of Judah; and he took the family of the Zarhites: and he brought the family of the Zarhites man by man; and Zabdi was taken: 18 And he brought his household man by man; and Achan, the son of Carmi, the son of Zabdi, the son of Zerah, of the tribe of Judah, was taken. 19 And Joshua said unto Achan, My son, give, I pray thee, glory to the LORD God of Israel, and make confession unto him; and tell me now what thou hast done; hide it not from me. 20 And Achan answered Joshua, and said, Indeed I have sinned against the LORD God of Israel, and thus and thus have I done: 21 When I saw among the spoils a goodly Babylonish garment, and two hundred shekels of silver, and a wedge of gold of fifty shekels weight, then I coveted them, and took them; and, behold, they are hid in the earth in the midst of my tent, and the silver under it. 22 So Joshua sent messengers, and they ran unto the tent; and, behold, it was hid in his tent, and the silver under it. 23 And they took them out of the midst of the tent, and brought them unto Joshua, and unto all the children of Israel, and laid them out before the LORD. 24 And Joshua, and all Israel with him, took Achan the son of Zerah, and the silver, and the garment, and the wedge of gold, and his sons, and his daughters, and his oxen, and his asses, and his sheep, and his tent, and all that he had: and they brought them unto the valley of Achor. 25 And Joshua said, Why hast thou troubled us? the LORD shall trouble thee this day. And all Israel stoned him with stones, and burned them with fire, after they had stoned them with stones. 26 And they raised over him a great heap of stones unto this day. So the LORD turned from the fierceness of his anger. Wherefore the name of that place was called, The valley of Achor, unto this day.
In the minds of critics, two sets of contextually innocent persons suffered here: the 36 men who died at Ai, and Achan's family other than himself. However, a social-contextual understanding leads to a different perspective, one that enables us to recognize that our sympathies for the "innocent" here are the result of our modern, Western prejudices.
Our primary source here is Kaminsky's Corporate Responsibility in the Hebrew Bible and a chapter [67ff] in which Kaminsky takes a close look at Joshua 7. Before beginning it is well to keep in mind that ancient societies, and most still around today, were/are highly collectivist in orientation. This does not mean that (as some have suggested in excess) persons had NO conception of themselves as individuals, but that the group-orientation was the primary focus for identity. The group came first, and the individual second. It is also well to remember what we have said elsewhere about ritual purity in the ancient world:
In ancient societies, purity codes "are a way of talking about what is proper for a certain place and a certain time...Pollution is a label attached to whatever is out of place with regard to the societiy's view of an orderly and safe world." It involves "drawing the lines that give definition to the world around us..." More than this: Purity in the ancient world "is fundamentally concerned with the ordering of the world and making sense of one's everyday experiences in light of that order, which is usually conceived as being a divine ordering of the cosmos..."
Ancient cultures like Israel's "draw extensive lines of purity, of clean and unclean, in an attempt to create a model of God's cosmic order and to help an individual locate his or her place in that order so that the person may know when pollution has been contracted and what needs to be done to dispel it, so that access to the holy God and his benefits will remain open."
Breaches of boundaries are "unclean". Hence the person partially leprous is ritually unclean; but the person who is totally covered with leprosy is ritually clean. Breaks in the skin or discharges likewise violate boundaries and are ritually unclean. From the Israelites food laws, something like a lobster which lives in the water, yet has legs, is ritually unclean because it breaks the boundaries between land and sea. Pilch and Malina [Handbook of Biblical Social Values, 24] also note the example of garments not being of mingled textiles (Lev. 19:19, Deut. 22:11)...
As shown in Education in Ancient Israel by James Crenshaw, the ancients knew well that human society in their time was only a few steps away from anarchy and chaos. Constant reminders were needed, and constant vigilance, to protect the social order. The interest in ritual purity represents a larger interest in the wholeness of the social order; maintaining order on one scale contributed to keeping order on a larger scale. "...[O]bserving these ordinances would be meaningful" for they "allowed the community of Israel to move in step with, or mirror, the divine order" and become "a living reflection of the character of the holy God in the midst of the world, a holy island of order in the midst of the Gentiles' aberrations."
In this light we are now prepared to take a closer look at Joshua 7. We should note to begin that the attack on Jericho was prefaced with these conditions (6:18-19):
And ye, in any wise keep yourselves from the accursed thing, lest ye make yourselves accursed, when ye take of the accursed thing, and make the camp of Israel a curse, and trouble it. But all the silver, and gold, and vessels of brass and iron, are consecrated unto the LORD: they shall come into the treasury of the LORD.
Any reader sees that Achan violated this by taking the gold; but why then was not Achan alone punished? The answer lies in the understanding of "sacred war" which had analogues in other ANE settings. Kaminsky notes the example in the Mesha inscription of Moab of an Israelite city in which Mesha had all the people killed (note for Skeptics: he literally says, "...I killed the entire population...") as "....a sanitation for Chemosh and Moab..." He did the same to another city in Israel.
Kaminsky locates other lesser analogues, but we have here a prime parallel to the OT incident in Josh. 7. Now note in 7:12 how Israel, because of Achan's sin, because "accursed" and connect this to the principles stated above on ritual purity. Achan had misappropriated the materials from Jericho, thus acquiring the same taboo status as the city itself; the ritual impurity in turn spread to his entire household.
Kaminsky suggests that this may be because all of Achan's family was considered his property, but the collective mindset above tells us what we need to know. All that was Achan's was rendered ritually impure by his violation (within which of course some of the family at least had to be complicit) and the restoration of order could only be accomplished via erasure of ritual impurity.
Some critics might claim we just make this stuff up, so I might note examples of another social group described as having the same qualities of belief. J. K. Campbell in Honour, Family and Patronage [37n] describes the Sarakatsan of Greece in much the same way as Kaminsky describes the Hebrews (emphasis added):
The Sarakatsan family is a system of closed relationships and a group with a recognized leader. It holds all property in common and controls the productive powers of all its members and the reproductive capabilities of its women. In principle all its members are held to be responsible for the action of any other member.
And Joseph Ginat in Blood Revenge  says similarly of the Bedouin of Palestine, who live in "co-liable" groups consisting of up to five generations:
A basic ideology of the co-liable group is collective responsibility -- any act or omission by one individual reflects on the group as a whole in the sense that the group is responsible for, and must accept, the consequences of that act or omission.
Modernists may well continue to decry this as unfair, but as Kaminsky notes, the concept of holiness in the OT "cuts across the Western dichotomy of the spiritual versus the physical; one's physical state is part of one's spiritual state" [88 -- see more on this, the Semitic Totality concept, link 2 below]
That which is unholy cannot withstand or remain in the presence of God. Kaminsky draws well an analogy to the "amoral" power of electricity: "Neither electricity nor holiness will act any differently simply in the basis of one's interior state or intentions." The deaths of the 36 men at Ai was more an indirect result of Achan's actions: the camp was no longer holy, and Israel was no longer under God's protection.
And thus we come to a form of communal responsibility: "Israel was held communally accountable for maintaining a fit environment in which God could manifest himself, and through this manifestation could radiate blessing to the rest of the terrestrial world."  Punishing Achan alone would not have transmitted this message accurately to people who were communally-oriented and collectivist in outlook.
To those who might still regard this as unfair, we repeat Kaminsky's concluding words: "...[A]lthough many modern thinkers would criticize the system of punishment advocated by Joshua 7 as inherently unfair because it does not treat each person as an autonomous individual, one wonders whether this narrative might not offer an implicit critique of the modern predisposition to view individuals as autonomous entities who only relate to their society when they freely choose to do so." [94-5]
The punishment of Achan's household reflected the realities and thoughts of the world they lived in, and no other reaction would have sufficed.