At what point in his life did David write Psalm 26, was it before or after the events of 2 Samuel 11?
According to its sub-title, it is a Psalm of David (c. 1010–970 BCE). According to Charles and Emilie Briggs, it is to be dated within the Persian period (539 to 333 BCE). See: A Critical and Exegetical Commentary on the Book of Psalms.
The Briggs describe the psalm as "a profession of integrity by a Levite, engaged in worshipping Yahweh in the temple choir."
A later editor by additions and changes introduces elements of prayer (v 1a, 9-11).
Note that this psalm generally is not considered a Davidic psalm by scholars, these are Pss 3, 7, 18, 34, 51, 52, 54, 56, 57, 59, 60, 63, 142.
As for its relation to 2 Samuel 11, the original ancient Hebrew manuscripts recorded the books of Samuel as only one book. The first time these books were divided was in the Septuagint, the Greek version of the Hebrew Scriptures, and they were referred to as the First and Second Books of Kingdoms. 1 and 2 Kings were referred to as the Third and Fourth Books of Kingdoms. When looking closely at the King James version of the Bible the titles are still arranged in this way.
Modern scholarly thinking posits that the entire Deuteronomistic history (including the Book of Samuel) was composed circa 630–540 BCE by combining a number of independent texts of various ages. The book of Samuel specifically is thought to be first committed to writing around 550 BCE, during the Babylonian Exile.