Summary: The vessel of the Lord must separate from evil to be functional and effective.
In the early part of the book of first Samuel, we read of the various leadership gaffes of the children of Eli - how they plundered the offerings of God, laid with the women at the tabernacle of the congregation and caused the people to transgress the laws of God. Despite the reproof and warning of their father about the looming consequences of their inordinate actions, they continued unrestrained.
In chapter four, Israel went to battle against the Philistines and they suffered a casualty of four thousand men. The elders of Israel therefore called that the Ark of covenant which represented the presence of God be brought from Shiloh to the camp so that they could defeat the Philistines by the hand of the Lord as it was at other times. The Ark was brought and there was a great shout in the camp, such that put the Philistines to flight.
The Philistines however took courage to attack the Israelites despite their knowledge of the terrible acts of the God of Israel against previous enemies of Israel. They encouraged themselves to fight because they did not want to become slaves to the Hebrews. They went in that strength and plundered the army of Israel killing 30,000 soldiers and capturing the Ark of covenant.
What happened that Israel suffered such a terrible defeat even with the Ark in the midst of the camp? Why could God not fight for them and save them from the hands of the Philistines? Apart from the fact that our God does not want to be placed on the reserve bench, He does not keep the company of sinners nor hearken to their prayers.
The truth is that the hearts of the people at that time had been turned away from God and that was why they did not even consult God before going to battle with the Philistines. And they only resulted to bringing the Ark into the camp when their weakness was brought to the fore by the first defeat they recorded against the enemy. They rejoiced at the presence of the Ark but their heart was still very far from God. They did not turn away from their evil way nor return to God yet they wanted Him to deliver them (2Chron 7:14).
Their second and paramount undoing were the carriers of the Ark, the accursed sons of Eli - Hophni and Phinehas. The vessel of the Lord must separate from evil to be functional and effective (Isaiah 52:11, 2Tim 2:19-22). God knows those who are His among the multitude that name His name and those that are His are those who have purged themselves of all kinds of filth and are sanctified unto good work. The sons of Eli who were the bearers of the Ark of covenant at that time failed woefully in this regard.
The story was however different when Samuel took over the office of the priest. He led the idolatrous Israel back to God and when the same Philistines came against them again at Mizpeh, Samuel fought the battle on the altar of God and the Lord discomfited the Philistines. Throughout the days of Samuel, the hand of the Lord subdued the Philistines. Israel even helped the Amorites out of the captivity of the Philistines (1Sam 7:3-14).